Never forget… to compress on NodeJS

After using expressJS for a while, I noticed that the HTTP responses from my nodeJS server weren’t compressed. Then I found out about a compressing method called gzip. This method is supported by browsers and speeds up HTTP connections.

To add compression to your node app you can use the npm package compression. This package used to come baked into expressJS. Now you have to installed it separately. Set it up like expressJS middleware. For more details view the docs.

// install it like expressJS middleware

Another way is to handle compression on the proxy level. NGINX is an example of web proxies.

Compression can significantly reduce the bytes transfered through the wire. Keep in mind that some clients are limited on the size of applications that they can handle. Maybe you are successful to compress your web app, but when the Android browser decompresses it, it can’t handle the size. Be mindful of the target clients.