Compression

Compression can greatly decrease the size of the response body, thereby increasing the speed of a web app. Use the compression middleware package to enable gzip compression.

Installation#

First install the required package:


$ npm i --save compression

Once the installation is complete, apply the compression middleware as global middleware.


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

For high-traffic websites in production, it is strongly recommended to offload compression from the application server - typically in a reverse proxy (e.g., Nginx). In that case, you should not 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