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?
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With