Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 342
Gabriel Florit Avatar asked Oct 06 '11 21:10

Gabriel Florit


1 Answers

You just need a wsgi middleware that gzips the response. See Gzipping all HTTP traffic with Pyramid or http://librelist.com/browser//flask/2010/6/14/gzip-compression/

like image 107
Tavis Rudd Avatar answered Sep 18 '22 15:09

Tavis Rudd