title: Rails: Passing controller variable to JS using ERB slows page?
body: <p>There are two ways I know of to pass variables defined in a controller (/action) to JS...</p>
  
  <h1>The official way is</h1>
  
  <p><strong>.js.erb</strong>:</p>
  
  <pre><code>var banana = "&lt;% @banana %&gt;"
  </code></pre>
  
  <h1><em>Another</em> way (that I'm currently using is)</h1>
  
  <p><strong>.html.erb</strong></p>
  
  <pre><code>&lt;span id="banana-variable" style="display:none"&gt;&lt;% @banana %&gt;&lt;/span&gt;
  </code></pre>
  
  <p><strong>.js</strong></p>
  
  <pre><code>var banana = $("#banana-variable").html()
  </code></pre>
  
  <p>This js file is loaded on multiple actions/views across the controller. It makes sense to me to not use a .erb extension: users cache it the first time they hit any action/view in the controller. They then won't have to download different versions of the file when they browse to different pages. Am I right?</p>