Skip to content

Commit a26b9f5

Browse files
committed
docs(compression): add notes on compression encodings
Includes information on why you may not want to use Brotli, and how to turn it off if you decide you don't want it.
1 parent 1a9f9bc commit a26b9f5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

content/techniques/compression.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ import * as compression from 'fastify-compress';
3737
// somewhere in your initialization file
3838
app.register(compression);
3939
```
40+
41+
By default, `fastify-compress` will compress Brotli payloads on the fly 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, and the slowness becomes obvious when e.g. serving responses from Nest's cache. 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.
42+
43+
To specify encodings, provide a second argument to `app.register`:
44+
45+
```typescript
46+
app.register(compression, { encodings: ['gzip', 'deflate'] });
47+
```
48+
49+
The above tells `fastify-compress` to only use gzip and deflate encodings, preferring gzip if the client supports both.

0 commit comments

Comments
 (0)