Question

I'm using express' res.end, etc to serve json as part of my rest api.

Google pagespeed is telling me to gzip it.

However according to this thread:

http://groups.google.com/group/express-js/browse_thread/thread/db1ad3307cb4f504/64f02170f616527c

it doesn't seem to be a good idea. After all that content is dynamic, and uncachable, so gzipping before every request doesn't seem like it'll be a net benefit.

Am I right? Or should I pursue gzip, thanks.

To be clear: static content (css, js) is already gzipped.

Was it helpful?

Solution

Gzip can make a great difference on your site performance, especially on slow / mobile connections, since it reduces the amount of data (and the amount of packets) which the browser has to receive.

I don't know about the specific implementation in Express, but using Gzip is a trade off between server CPU time and bandwidth. You consume use (slightly) more CPU on the server to compress your content, but you reduce bandwidth usage, page load time, and the amount of time your web server has to keep a socket open while sending data to the browser. Every best-practice guide and page speed analysis software (such as Google Page Speed, Web Page Test and so on) strongly suggests using Gzip, so I presume the effort is worth it.

Concerning how to achieve it in Express, I personally use Nginx to proxy all requests to my Express app (and serve static content), so I simply configured Nginx to gzip HTML, CSS, Javascript and some other types of resources before sending them to the client.

Some references:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top