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