Static Asset Packaging for Rails 3 on Heroku
:cache => true option to the
stylesheet_link_tag helpers to provide asset concatenation at no cost to the developer.
As time went on, our needs outgrew the capabilities of
Of course, static asset packaging wasn’t the only part of the Rails ecosystem that was undergoing major changes during this time. An increased emphasis on ease of deployment saw the rise of Capistrano, Passenger, and eventually Heroku, which offers hands-free system maintenance and simple
git push heroku deployment. This simplification is not without trade-offs, though; you can only write to your app’s
tmp directory and the lack of root access means that you can’t install additional software. Both of these limitations have ramifications for static asset packaging, namely:
:cache => trueand standard AssetPackager work by writing files into your app’s
publicdirectory, which, as you can likely guess, is verboten.
Jammit has several compression options, but all of them require Java support, which we don’t have on Heroku. You have the option of compressing your assets and checking them into your repository by hand, but I for one can’t stand putting build artifacts in the repo.
I’ve seen a lot of questions about how to do static asset packaging on Heroku and just as many bad answers (which I’ll avoid linking to here). The best solution we’ve found uses AssetPackager along with this fork of Heroku Asset Packager that has been modified to work with Rails 3. It’s not the sexiest solution, but it works, and you’ll never have to think about it again.