As you might already know, GZip is one of the easiest wins you can make to improve the performance of your website. Generally, GZipping will reduce the size of your HTTP responses by 70%.
If you’re using Express, it doesn’t GZip static assets out-of-the-box so you’ll be missing out on the many benefits of GZip.
Here’s how you enable it:
- Add this lines to your server.js (or equivalent file where you define middleware and startup your server)
1 2 3 4
express.compress() must be before express.static(). This is where the magic happens :)
Restart your server, and voila… GZip!
Inspect the HTTP response headers and you should see Content-Encoding: gzip