Using compression middleware in Node/Express
If you’re using ExpressJS to host your server, there’s a small performance tweak that you can do (works on universally on any kind of server – HTML templates to JSON REST APIs to image servers) – which is to enable GZIP compression.
The changed required to do it should be very simple. First install the compression npm package
npm install --save compression
app.js (or wherever you start your express server), modify the code to include the compression middleware like this
var express = require('express); var app = express(); var compression = require('compression'); app.use(compression()); // Rest of your app code // app.get (endpoint, callback) // app.listen(port, callback)
This should easily reduce page loads time to the order of 15-20%.
For example, page load before compression middleware added
And Page load time after compression is added
You must be logged in to post a comment.