Skip to content

Commit 8f66c22

Browse files
authored
docs: improve compress example (#3968)
1 parent 6f4ff92 commit 8f66c22

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

examples/compression/false/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Gzip Compression
2+
3+
Website gzip compression makes it possible to reduce the file size of a file
4+
to roughly 30% of its original size before the files are sent to the browser.
5+
6+
It is enabled by default. To disable it set `compresss` option to `false`.
7+
8+
## false
9+
10+
**webpack.config.js**
11+
12+
```js
13+
module.exports = {
14+
// ...
15+
devServer: {
16+
compress: false,
17+
},
18+
};
19+
```
20+
21+
Usage via CLI:
22+
23+
```console
24+
npx webpack serve --open --no-compress
25+
```
26+
27+
### What should happen
28+
29+
1. The script should open `http://localhost:8080/`.
30+
2. Files being sent to the browser from the `webpack` bundle should be gzipped.
31+
3. Open the console in your browser's devtools and select the _Network_ tab.
32+
4. Find `main.js`. The response headers should not contain `Content-Encoding: gzip`.
33+
34+
## Notes
35+
36+
Some browsers, such as Chrome, won't show the `Content-Encoding: gzip` within
37+
the _Response Headers_. This has been documented [here](https://github.com/expressjs/compression/issues/96).
38+
39+
To enable `Content-Encoding` for _Response Headers_ in Chrome, you can follow
40+
[this tutorial](https://www.youtube.com/watch?v=47R6uv0RKCk).
File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
// our setup function adds behind-the-scenes bits to the config that all of our
4+
// examples need
5+
const { setup } = require("../../util");
6+
7+
module.exports = setup({
8+
context: __dirname,
9+
entry: "./app.js",
10+
devServer: {
11+
compress: false,
12+
},
13+
});

examples/compression/README.md renamed to examples/compression/true/README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ npx webpack serve --open --compress
3131
3. Open the console in your browser's devtools and select the _Network_ tab.
3232
4. Find `main.js`. The response headers should contain `Content-Encoding: gzip`.
3333

34-
## false
35-
36-
**webpack.config.js**
37-
38-
```js
39-
module.exports = {
40-
// ...
41-
devServer: {
42-
compress: false,
43-
},
44-
};
45-
```
46-
47-
Usage via CLI:
48-
49-
```console
50-
npx webpack serve --open --no-compress
51-
```
52-
53-
### What should happen
54-
55-
1. The script should open `http://localhost:8080/`.
56-
2. Files being sent to the browser from the `webpack` bundle should be gzipped.
57-
3. Open the console in your browser's devtools and select the _Network_ tab.
58-
4. Find `main.js`. The response headers should not contain `Content-Encoding: gzip`.
59-
6034
## Notes
6135

6236
Some browsers, such as Chrome, won't show the `Content-Encoding: gzip` within

examples/compression/true/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
const target = document.querySelector("#target");
4+
5+
target.classList.add("pass");
6+
target.innerHTML = "Success!";

examples/compression/webpack.config.js renamed to examples/compression/true/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// our setup function adds behind-the-scenes bits to the config that all of our
44
// examples need
5-
const { setup } = require("../util");
5+
const { setup } = require("../../util");
66

77
module.exports = setup({
88
context: __dirname,

0 commit comments

Comments
 (0)