Just some quick notes for those tuning their Cedar Rails 3.1 apps.

I love heroku because it takes away most of my server hassles. Also, caches are awesome. Unfortunately the new cedar stack—which you need to use to for rails 3.1—doesn’t hook you up with a CDN or a Cache (properly) by default (I think it should, really).

Heroku Cedar passes asset requests directly through to the Rails stack. They achieve this by injecting a plugin to force you to serve static assets from rails. But they don’t set any caching headers, so in fact these assets aren’t cached by Rack::Cache or by CDNs.

So if you want to get all the benefits of caching etc easily, you need to make sure you set these headers inside rails. We usually set things to expire in 1 year, as digests mean that they will never change. So inside production.rb, set:

  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=31536000"

Easy-peasy-lemon-squeezy.

Oh, so this means there is no need to disable precompiled assets to use Cloudfront. Just point it directly at your instance and set your asset host.

Tom Coleman

Co-creator of bindle.me, searching for simplicity, quality and elegance in technology, products and code.

See all Tom Coleman's posts
Leave a Reply

  • Search: