Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way to serve pre-gzipped assets in Rails 3.2 on Heroku Cedar?

I have a Rails 3.2 app that I'm deploying on the Heroku Cedar stack. This means that the app itself is responsible for serving its static assets. I'd like these assets to be gzipped, so I've inserted Rack::Deflater in my middleware stack in production.rb:

middleware.insert_after('Rack::Cache', Rack::Deflater)

...and curl tells me that this works as advertised.

However, since Heroku is going to all the effort of running rake assets:precompile, producing a bunch of pre-gzipped assets, I'd quite like to use those (rather than letting Rack::Deflater do all the work again). I've seen recipes for serving these up with nginx (no use on Heroku), and with CDNs (not wanting to use a CDN just yet), but I haven't seen anything that can just run standalone. I've hacked together a rack middleware to do this, but I was wondering if this is the best way to go about it?

like image 435
Guy Bolton King Avatar asked Mar 21 '12 20:03

Guy Bolton King


1 Answers

Since deflater is after rack cache, then deflator will only have to do the work once, and after that the compressed assets will be served from rack cache (assuming the cache is big enough so that they don't get bumped out occasionally).

That said, your middleware looks pretty cool, and you should make make it a gem and blog about it, maybe it will be what people start to use :-)

like image 63
John Bachir Avatar answered Oct 15 '22 09:10

John Bachir