herokuruby-on-rails-3.1gzipexpires-headercedar

How to get Gzip and Expires Header on a Rails 3.1.1 app on Heroku Cedar?


I'm running a Rails 3.1.1 application on Heroku Cedar. By default this stack doesn't Gzip and set Expires Headers on assets. There is some doc about that, but it's not very clear : http://devcenter.heroku.com/articles/http-routing

Can somebody give me the piece of code to activate that ?

Thank you very much


Solution

  • Cedar doesn't use Nginx, so you have to gzip assets yourself with Rack::Deflater, like so :

    # config.ru
    require ::File.expand_path('../config/environment',  __FILE__)
    use Rack::Deflater
    run YourApp::Application
    

    Also you can set headers for static files directly in your app :

    # config/environments/production.rb
    config.static_cache_control = "public, max-age=3600"
    

    Finally you're probably better off setting up Rack::Cache to replace Varnish caching. See this blog post for more infos.