Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a GZIP compression middleware or not?

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).

like image 205
Attila O. Avatar asked Dec 02 '10 19:12

Attila O.


People also ask

Which is better compress or gzip?

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.

What is gzip middleware?

GZipMiddleware compresses content for browsers that understand GZip compression (all modern browsers).

Does gzip improve performance?

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.

How efficient is gzip compression?

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.


1 Answers

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".

like image 141
Robert Kluin Avatar answered Sep 17 '22 21:09

Robert Kluin