diff --git a/content/techniques/compression.md b/content/techniques/compression.md index bb77fea4d3..233c7522a8 100644 --- a/content/techniques/compression.md +++ b/content/techniques/compression.md @@ -38,7 +38,15 @@ import compression from '@fastify/compress'; await app.register(compression); ``` -By default, `@fastify/compress` will use Brotli compression (on Node >= 11.7.0) when browsers indicate support for the encoding. While Brotli is quite efficient in terms of compression ratio, it's also quite slow. Due to this, you may want to tell fastify-compress to only use deflate and gzip to compress responses; you'll end up with larger responses but they'll be delivered much more quickly. +By default, `@fastify/compress` will use Brotli compression (on Node >= 11.7.0) when browsers indicate support for the encoding. While Brotli can be quite efficient in terms of compression ratio, it can also be quite slow. By default, Brotli sets a maximum compression quality of 11, although it can be adjusted to reduce compression time in lieu of compression quality by adjusting the `BROTLI_PARAM_QUALITY` between 0 min and 11 max. This will require fine tuning to optimize space/time performance. An example with quality 4: + +```typescript +import { constants } from 'zlib'; +// somewhere in your initialization file +await app.register(compression, { brotliOptions: { params: { [constants.BROTLI_PARAM_QUALITY]: 4 } } }); +``` + +To simplify, you may want to tell `fastify-compress` to only use deflate and gzip to compress responses; you'll end up with potentially larger responses but they'll be delivered much more quickly. To specify encodings, provide a second argument to `app.register`: