Having worked with Django, I've seen that people tend to reccommend the use of GZIP Middleware to compress HTML pages.
However, the WSGI v1.0 specification tells us:
(Note: 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. See Other HTTP Features below, for more details.)
This suggests that compression should be left to the server/gateway. Which makes sense, as the server is probably much faster in doing that. Also, it might prefer SDCH over gzip, as most modern Chrome/Chromium browsers support it.
So my question remains, should I use a middleware to compress my responses or not? Specifically, what is the right choice for Google App Engine?
EDIT:
The Pylons Book also contains an example gzip middleware.
I didn't mention that my framework of choice is Pyramid (ex-repoze.bfg).
TL;DR: gzip is better than compress . compress is slower than gzip -1 when compressing, it compresses only half as well, but. it is 29% faster when decompressing.
GZipMiddleware compresses content for browsers that understand GZip compression (all modern browsers).
Gzip is a fast and easy way to improve page speed performance while still delivering a high-quality experience to your users. See if your website supports gzip by running a free speed test, and sign up for a free trial for more insights into your website's performance.
However, in practice, GZIP performs best on text-based content, often achieving compression rates of as high as 70-90% for larger files, whereas running GZIP on assets that are already compressed via alternative algorithms (for example, most image formats) yields little to no improvement.
App Engine already does compress the content, if the client supports it.
If the client sends HTTP headers with the request indicating that the client can accept compressed (gzipped) content, App Engine compresses the response data automatically and attaches the appropriate response headers. It uses both the Accept-Encoding and User-Agent request headers to determine if the client can reliably receive compressed responses. Custom clients can force content to be compressed by specifying both Accept-Encoding and User-Agent headers with a value of "gzip".
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