Skip to content

Commit f540c48

Browse files
authored
docs(readme): add zstandard compression information (#407)
1 parent 10a7bdc commit f540c48

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.cspell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"Brotli’s",
1414
"BROTLI",
1515
"brotli",
16+
"Zstandard",
17+
"Zstandard’s",
18+
"zstd",
1619
"Koppers",
1720
"sokra",
1821
"precache",

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,40 @@ module.exports = {
524524
[!NOTE] Brotli’s `BROTLI_PARAM_QUALITY` option is functionally equivalent to zlib’s `level` option.
525525
You can find all Brotli’s options in [the relevant part of the zlib module documentation](https://nodejs.org/api/zlib.html#zlib_class_brotlioptions).
526526

527+
### Using Zstandard
528+
529+
[Zstandard](https://facebook.github.io/zstd/) (zstd) is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.
530+
531+
Node.js 22.15.0 and later includes [native support](https://nodejs.org/api/zlib.html#zlibcreatezstdcompressoptions) for Zstandard compression in its `zlib` module.
532+
533+
You can take advantage of this built-in support for zstd in Node 22.15.0 and later by just passing in the appropriate `algorithm` to the CompressionPlugin:
534+
535+
**webpack.config.js**
536+
537+
```js
538+
const zlib = require("zlib");
539+
540+
module.exports = {
541+
plugins: [
542+
new CompressionPlugin({
543+
filename: "[path][base].zst",
544+
algorithm: "zstdCompress",
545+
test: /\.(js|css|html|svg)$/,
546+
compressionOptions: {
547+
params: {
548+
[zlib.constants.ZSTD_c_compressionLevel]: 10,
549+
},
550+
},
551+
threshold: 10240,
552+
minRatio: 0.8,
553+
deleteOriginalAssets: false,
554+
}),
555+
],
556+
};
557+
```
558+
559+
You can find all Zstandard's options in [the relevant part of the zlib module documentation](https://nodejs.org/api/zlib.html#class-zstdoptions).
560+
527561
### Multiple compressed versions of assets for different algorithm
528562

529563
**webpack.config.js**

0 commit comments

Comments
 (0)