Compression

We can improve page load times further by compressing static files. Express includes the compress middleware, which will gzip an HTTP response. Let's edit the Express server, /vision-web/lib/express/index.js, and add the compress middleware, as follows:

app.set('views', 'views');
app.use(express.logger({ immediate: true, format: 'dev' }));
app.use(express.compress());

If you visit the homepage for our application and check the response headers via your browser tools for all of the resources served, you should see this:

Content-Encoding: gzip

Get Advanced Express Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.