Skip to content

Commit 1a9f9bc

Browse files
committed
docs(compression): add more detail to Fastify compression instructions
According to fastify-compress docs, the plugin will auto-register. This isn't actually the case, at least in a Nest project. The instructions here mirror the (slightly more) manual approach that worked in an app I'm building.
1 parent e76be03 commit 1a9f9bc

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

content/techniques/compression.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
### Compression
22

3-
Compression can greatly decrease the size of the response body, thereby increasing the speed of a web app. Use the [compression](https://github.com/expressjs/compression) middleware package to enable gzip compression.
3+
Compression can greatly decrease the size of the response body, thereby increasing the speed of a web app.
44

5-
#### Installation
5+
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.
6+
7+
#### Use with Express (default)
8+
9+
Use the [compression](https://github.com/expressjs/compression) middleware package to enable gzip compression.
610

711
First install the required package:
812

913
```bash
1014
$ npm i --save compression
1115
```
1216

13-
Once the installation is complete, apply the compression middleware as global middleware.
17+
Once the installation is complete, apply the compression middleware as a global middleware.
1418

1519
```typescript
1620
import * as compression from 'compression';
1721
// somewhere in your initialization file
1822
app.use(compression());
1923
```
2024

21-
> info **Hint** If using the `FastifyAdapter`, consider using [fastify-compress](https://github.com/fastify/fastify-compress) instead.
25+
#### Use with Fastify
2226

23-
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.
27+
If using the `FastifyAdapter`, you'll want to use [fastify-compress](https://github.com/fastify/fastify-compress):
28+
29+
```bash
30+
$ npm i --save fastify-compress
31+
```
32+
33+
Once the installation is complete, apply the fastify-compress middleware as a global middleware.
34+
35+
```typescript
36+
import * as compression from 'fastify-compress';
37+
// somewhere in your initialization file
38+
app.register(compression);
39+
```

0 commit comments

Comments
 (0)