Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 433
Camille Avatar asked Oct 17 '11 10:10

Camille


2 Answers

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.

like image 77
DuoSRX Avatar answered Oct 26 '22 13:10

DuoSRX


Shameless plug - I created a gem which enables compression, but avoids compressing images.

https://github.com/romanbsd/heroku-deflater

like image 43
Roman Avatar answered Oct 26 '22 11:10

Roman