How to enable gzip compression on Heroku Cedar (Python/Flask/Gunicorn)

Gabriel Florit picture Gabriel Florit · Oct 6, 2011 · Viewed 8k times · Source

How do I enable GZIP compression on the new Heroku Cedar stack? This is straight from their site:

Since requests to Cedar apps are made directly to the application server – not proxied through an HTTP server like nginx – any compression of responses must be done within your application. For Rack apps, this can be accomplished with the Rack::Deflater middleware. For gzipped static assets, make sure that Rack::Deflater is loaded before ActionDispatch::Static in your middleware stack.

If I'm reading this correctly, my Python application code is now responsible for gzipping the responses? How would I go about compressing my static assets (e.g. css/js)? I'm using Flask and GUnicorn.

Answer

Tavis Rudd picture Tavis Rudd · Oct 21, 2011