Skip to content

Commit ff3ceeb

Browse files
khalwatevilebottnawi
authored andcommitted
docs: add “Using Brotli” (#119)
Signed-off-by: Andrew Welch <[email protected]>
1 parent 264efa3 commit ff3ceeb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,33 @@ module.exports = {
278278
}
279279
```
280280

281+
### Using Brotli
282+
283+
[Brotli](https://en.wikipedia.org/wiki/Brotli) is a compression algorithm originally developed by Google, and offers compression superior to gzip.
284+
285+
Node 11.7.0 and later has [native support](https://nodejs.org/api/zlib.html#zlib_zlib_createbrotlicompress_options) for Brotli compression in its zlib module.
286+
287+
We can take advantage of this built-in support for Brotli in Node 11.7.0 and later by just passing in the appropriate `algorithm` to the CompressionPlugin:
288+
289+
```js
290+
// in your webpack.config.js
291+
module.exports = {
292+
plugins: [
293+
new CompressionPlugin({
294+
filename: '[path].br[query]',
295+
algorithm: 'brotliCompress',
296+
test: /\.(js|css|html|svg)$/,
297+
compressionOptions: { level: 11 },
298+
threshold: 10240,
299+
minRatio: 0.8,
300+
deleteOriginalAssets: false
301+
})
302+
]
303+
}
304+
```
305+
306+
**N.B.:** The `level` option matches `BROTLI_PARAM_QUALITY` [for Brotli-based streams](https://nodejs.org/api/zlib.html#zlib_for_brotli_based_streams)
307+
281308
## Contributing
282309

283310
Please take a moment to read our contributing guidelines if you haven't yet done so.

0 commit comments

Comments
 (0)