Only assets that compress better than this ratio are processed (minRatio = Compressed Size / Original Size).
For example, if you have a image.png file with a size of 1024 bytes, and its compressed version is of 768 bytes, the minRatio is 0.75.
In other words, assets will be processed only when the ratio of Compressed Size / Original Size is less than the specified minRatio.
You can use a value of 1 to process assets that are smaller than or equal to the original size.
Use a value of Infinity to process all assets, even if they are larger than the original size or their original size is 0 bytes (useful when you are pre-zipping all assets for AWS).
Use a value of Number.MAX_SAFE_INTEGER to process all assets even if they are larger than the original size, excluding assets with their original size is 0 bytes.
webpack.config.js
module.exports = { plugins: [ new CompressionPlugin({ // Compress all assets, including files with `0` bytes size // minRatio: Infinity // Compress all assets, excluding files with `0` bytes size // minRatio: Number.MAX_SAFE_INTEGER minRatio: 0.8, }), ],};
filename
Type:
type filename = string | ((pathdata: PathData) => string);
Default: "[path][base].gz"
The target asset filename.
string
For example, given an asset path: assets/images/image.png?foo=bar#hash:
[path] is replaced with the directories of the original asset, including the trailing / (assets/images/).
[file] is replaced with the path of the original asset (assets/images/image.png).
[base] is replaced with the base name ([name] + [ext]) of the original asset (image.png).
[name] is replaced with the name of the original asset (image).
[ext] is replaced with the extension of the original asset, including the . (.png).
[query] is replaced with the query of the original asset, including the ? (?foo=bar).
[fragment] is replaced with the fragment (in the concept of URL it is called hash) of the original asset (#hash).
module.exports = { plugins: [ new CompressionPlugin({ filename(pathData) { // The `pathData` argument contains all placeholders - `path`/`name`/`ext`/etc // Available properties described above, for the `String` notation if (/\.svg$/.test(pathData.filename)) { return "assets/svg/[path][base].gz"; } return "assets/js/[path][base].gz"; }, }), ],};
Brotli is a compression algorithm originally developed by Google, and offers compression superior to gzip.
Node.js v10.16.0 and later includes native support for Brotli compression in its zlib module.
You can take advantage of this built-in support for Brotli in Node 10.16.0 and later by just passing in the appropriate algorithm to the CompressionPlugin:
Zstandard (zstd) is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.
Node.js 22.15.0 and later includes native support for Zstandard compression in its zlib module.
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: