Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 assets caching on heroku

Even if I already rake assets:precompile-ed all my assets, I still seem to have a hard to getting heroku to cache them correctly. I keep getting things like

2011-06-04T16:40:20+00:00 app[web.1]: cache: [GET /assets/application-516c0fa9926527ab92d849148e557ee6.css] stale, invalid, store
2011-06-04T16:40:22+00:00 app[web.1]: cache: [GET /assets/logo-3a84e73bd76ca1ab9629d0a92eac7d4f.png] stale, invalid, store

from my log. Although it seems like I'm getting a HTTP 304 when I inspect with firebug. Am I doing anything wrong?

like image 211
Godfrey Chan Avatar asked Jun 04 '11 16:06

Godfrey Chan


People also ask

How do I Precompile assets in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

How can you implement caching in Rails?

In order to use page and action caching you will need to add actionpack-page_caching and actionpack-action_caching to your Gemfile . By default, caching is only enabled in your production environment. You can play around with caching locally by running rails dev:cache , or by setting config. action_controller.

What does Rails assets Precompile do?

In production, Rails precompiles these files to public/assets by default. The precompiled copies are then served as static assets by the web server. The files in app/assets are never served directly in production.


1 Answers

This blog post has good answers and several options. The blog post doesn't look to serious, but this is a recommended read.

full url: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

Letting Varnish cache and serve it as static content is brilliant, no need for rake tasks precompiling.

UPDATE 20th march 2012

the world changes fast. the Cedar stack at heroku is built for this. heroku create myapp --stack cedar Remember to add this line of code in your application.rb to compile on deploy.

config.assets.initialize_on_precompile = false 

/UPDATE

like image 187
oma Avatar answered Oct 11 '22 23:10

oma