Compression

Compression can greatly decrease the size of the response body and hence increase the speed of a web app. Use the compression middleware to enable gzip compression.

Installation#

Firstly, install the required package:


$ npm i --save compression

Once the installation is completed, apply it as a global middleware.


import * as compression from 'compression';
// somewhere in your initialization file
app.use(compression());
Hint If you work with FastifyAdapter, consider using fastify-compress instead.

For a high-traffic website in production, the best way to put compression in place is to implement it at a reverse proxy level. In that case, you do not need to use compression middleware.

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.

Principal Sponsor

Sponsors / Partners

Become a sponsor