title: Rails 3.2 precompressing selected assets
body: <p>So, I have the following line of code in my <code>&lt;head&gt;</code>, inside <code>app/views/layouts/application.html.erb</code>:</p>
  <pre><code>&lt;%= stylesheet_link_tag &quot;front&quot;, :media =&gt; &quot;all&quot; %&gt;
  </code></pre>
  <p>Which works fine in development, but when I switch to production it breaks because it's not precompiled, so I run <code>rake assets:precompile</code>, which adds a bunch of files to my public directory, also fine, but all the css and js files are names like:</p>
  <ul>
  <li><code>application-digest.ext</code></li>
  <li><code>application-digest.ext.gz</code></li>
  <li><code>application.ext</code></li>
  <li><code>application.ext.gz</code></li>
  </ul>
  <p>Where <code>ext</code> is either <code>css</code> or <code>js</code>, and <code>digest</code> obvously varies.</p>
  <p>Image files just come with <code>name.ext</code> and <code>name-digest.ext</code> versions.</p>
  <p>So, when navigating to the page, I get an <code>ActionView::Template::Error</code> telling me <code>front.css isn't precompiled</code>.</p>
  <p>Since I have different layouts for different controllers (and the <code>FrontController</code> uses the <code>application.html.erb</code> layout, if that matters), I wouldn't like to include <em>all</em> of the css or js files inside all the controller layouts, because it's just shameful waste of bandwidth.</p>
  <p><strong>How do I tell rails to compile all the files inside</strong> <code>app/assets</code> <strong>individually?</strong></p>
  <hr />
  <p>I managed to &quot;fix&quot; the problem using live-comilation by setting <code>config.assets.compile = true</code> inside <code>config/environments/production.rb</code>, but I keep reading everywhere that's not the best way of handling assets<sup>[1]</sup>, because it wastes a lot of resources.</p>
  <p>The app is hosted on Heroku.</p>
  <hr />
  <p>[1]: <a href="http://guides.rubyonrails.org/asset_pipeline.html#live-compilation" rel="nofollow noreferrer">official Ruby on Rails guide page</a>: <em>&quot;This mode uses more memory, performs more poorly than the default and is not recommended.&quot;</em></p>