Files
docs.nestjs.com/content/techniques/compression.md
2019-02-13 18:24:50 +01:00

857 B

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());

info 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.