I recently migrated a Ruby on Rails 3.1 app from the Heroku Bamboo stack to Heroku Cedar. If you’re doing the same, here are a few notes to help avoid snags on getting the Rails Asset Pipeline working efficiently.
Unlike Bamboo, Cedar does not offer Varnish as a reverse proxy cache, nor does it automatically gzip content. You need to do it yourself. Heroku recommends:
- Use memcached, with Dalli as the memcached client. Make sure to follow the Rails 3 section.
- Use Rack::Cache as a substitute for Varnish. Heroku links to this article which explains how to integrate Heroku with Rack::Cache. I couldn’t get it to work, so I hunted around and pieced together the folllowing riff.
require 'rack-cache'
My::Application.configure do
...
# Enable Rack::Cache
config.middleware.use Rack::Cache,
:metastore => "memcached://#{ENV['MEMCACHE_SERVERS']}/meta",
:entitystore => "memcached://#{ENV['MEMCACHE_SERVERS']}/body"
You can also set HTTP headers in production.rb as follows. (3600 is an example value, make this whatever you want.)
# Add HTTP headers to cache static assets for an hour config.static_cache_control = "public, max-age=3600"
And you may want to add this to your config.ru to get gzip working:
use Rack::Deflater
References:
Recent Comments