Pre-generating cached Stylesheets and Javascripts with Rails 2.0

We just switched autoki over to Rails 2.0.2 in the last days. While the transition we replaced the asset_packager plugin with the new Rails 2.0 :cache => true option in stylesheet_link_tag/javascript_include_tag.

As our assets (public/*) are served from an apache webserver that has its own checkout of the project, we can’t let Rails generate the all.css/all.js files on the fly when the first request comes in. Instead we have to pre-generate them at deployment. For asset_packager we had a capistrano task that did just that. Rails doesn’t have that. Instead the logic to generate the files is built right into the link/include methods in the AssetTagHelper(!). So now we are simply doing this in our capistrano recipe:

Fire up a mongrel, curl the start page, bring it back down. Feels a bit overkill but it works. (at least I hope it will when I’ll first try it later today)

Tags: , , , ,

6 Responses to “Pre-generating cached Stylesheets and Javascripts with Rails 2.0”

  1. Ani*ka Says:

    I hope so too…but perhaps you won’t try it only a few minutes before feierabend…;-)

  2. Alexander Lang Says:

    you bet i will. again. why do people never learn from their past mistakes? like yesterday.

  3. Ani*ka Says:

    I don’t take bets…;-)

  4. Alexander Lang Says:

    i did it and of course it didn’t work because there’s a typo in the script. (fixed it)

  5. Alexander Lang Says:

    of course this still doesn’t work - stale pid files, mongrel still running because the previous deployment didn’t go through and that. more on that later.

  6. upstream - agile web (2.0) softwareentwicklung » Pregenerating assets in Rails 2.0 revisited Says:

    [...] a previous post I wrote about how we wanted to pregenerate our packed assets simply by firing up a mongrel on [...]

Leave a Reply