14
votes

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.

2
Maybe it doesn't feel right but surely they are telling you that. On python.org you have the documentation regarding gzip usage: docs.python.org/library/gzip.htmlgforcada
just playing devils advocate here - why do you need to use gzip? You're not paying for bandwidth in/out of Heroku so why the need to compress?John Beynon
I need to compress because my users will prefer to load up a page that weighs 300KB instead of 1MB!Gabriel Florit

2 Answers

1
votes

According to the WSGI spec, published 2003, apps shouldn't gzip responses but leave that to the server (presumed to be Apache, running the app CGI-stylee).

applications and middleware must not apply any kind of Transfer-Encoding to their output, such as chunking or gzipping; as "hop-by-hop" operations, these encodings are the province of the actual web server/gateway.

But today in 2013, often the app is the server. WSGI didn't anticipate this. That's a problem, according to http://www.b-list.org/weblog/2009/aug/10/wsgi/

WSGI’s curious insistence on compatibility with CGI also means that, here in 2009, the Python web-development world still hasn’t been able to significantly improve on 1997’s application programming model.