Skip to content

Commit bcfeae0

Browse files
Merge pull request nestjs#2890 from eugleenyc/compression
Docs(/techniques/compression): Brotli compression performance
2 parents 40dbb2b + 723a6fd commit bcfeae0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

content/techniques/compression.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ import compression from '@fastify/compress';
3838
await app.register(compression);
3939
```
4040

41-
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.
41+
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:
42+
43+
```typescript
44+
import { constants } from 'zlib';
45+
// somewhere in your initialization file
46+
await app.register(compression, { brotliOptions: { params: { [constants.BROTLI_PARAM_QUALITY]: 4 } } });
47+
```
48+
49+
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.
4250

4351
To specify encodings, provide a second argument to `app.register`:
4452

0 commit comments

Comments
 (0)