Gathering detailed insights and metrics for compression-webpack-plugin
Gathering detailed insights and metrics for compression-webpack-plugin
Gathering detailed insights and metrics for compression-webpack-plugin
Gathering detailed insights and metrics for compression-webpack-plugin
@types/compression-webpack-plugin
Stub TypeScript definitions entry for compression-webpack-plugin, which provides its own types definitions
vue-cli-plugin-compression
Prepare compressed versions of assets to serve them with Content-Encoding
@theia/compression-webpack-plugin
Prepare compressed versions of assets to serve them with Content-Encoding
@micburks/compression-webpack-plugin
Prepare compressed versions of assets to serve them with Content-Encoding
Prepare compressed versions of assets to serve them with Content-Encoding
npm install compression-webpack-plugin
Typescript
Module System
Min. Node Version
Node Version
NPM Version
89.8
Supply Chain
68.9
Quality
78.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
408,651,594
Last Day
36,315
Last Week
1,066,650
Last Month
4,687,112
Last Year
59,496,629
MIT License
1,428 Stars
280 Commits
109 Forks
24 Watchers
5 Branches
48 Contributors
Updated on Jun 25, 2025
Minified
Minified + Gzipped
Latest Version
11.1.0
Package Id
compression-webpack-plugin@11.1.0
Unpacked Size
36.20 kB
Size
8.93 kB
File Count
6
NPM Version
10.2.3
Node Version
18.19.0
Published on
Feb 27, 2024
Cumulative downloads
Total Downloads
Last Day
-9.6%
36,315
Compared to previous day
Last Week
-11.1%
1,066,650
Compared to previous week
Last Month
-4.8%
4,687,112
Compared to previous month
Last Year
-9.2%
59,496,629
Compared to previous year
2
1
29
Prepare compressed versions of assets to serve them with Content-Encoding.
To begin, you'll need to install compression-webpack-plugin
:
1npm install compression-webpack-plugin --save-dev
or
1yarn add -D compression-webpack-plugin
or
1pnpm add -D compression-webpack-plugin
Then add the plugin to your webpack
config. For example:
webpack.config.js
1const CompressionPlugin = require("compression-webpack-plugin"); 2 3module.exports = { 4 plugins: [new CompressionPlugin()], 5};
And run webpack
via your preferred method.
test
Type:
1type test = string | RegExp | Array<string | RegExp>;
Default: undefined
Include all assets that pass test assertion.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 test: /\.js(\?.*)?$/i, 5 }), 6 ], 7};
include
Type:
1type include = string | RegExp | Array<string | RegExp>;
Default: undefined
Include all assets matching any of these conditions.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 include: /\/includes/, 5 }), 6 ], 7};
exclude
Type:
1type exclude = string | RegExp | Array<string | RegExp>;
Default: undefined
Exclude all assets matching any of these conditions.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 exclude: /\/excludes/, 5 }), 6 ], 7};
algorithm
Type:
1type algorithm = 2 | string 3 | (( 4 input: Buffer, 5 options: CompressionOptions, 6 callback: ( 7 error: Error | null | undefined, 8 result: 9 | string 10 | ArrayBuffer 11 | SharedArrayBuffer 12 | Uint8Array 13 | readonly number[] 14 | { 15 valueOf(): ArrayBuffer | SharedArrayBuffer; 16 } 17 | { 18 valueOf(): string | Uint8Array | readonly number[]; 19 } 20 | { 21 valueOf(): string; 22 } 23 | { 24 [Symbol.toPrimitive](hint: "string"): string; 25 }, 26 ) => void, 27 ) => any);
Default: gzip
The compression algorithm/function.
Note
If you use custom function for the
algorithm
option, the default value of thecompressionOptions
option is{}
.
string
The algorithm is taken from zlib.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 algorithm: "gzip", 5 }), 6 ], 7};
function
Allow to specify a custom compression function.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 algorithm(input, compressionOptions, callback) { 5 return compressionFunction(input, compressionOptions, callback); 6 }, 7 }), 8 ], 9};
compressionOptions
Type:
1type compressionOptions = { 2 flush?: number; 3 finishFlush?: number; 4 chunkSize?: number; 5 windowBits?: number; 6 level?: number; 7 memLevel?: number; 8 strategy?: number; 9 dictionary?: Buffer | TypedArray | DataView | ArrayBuffer; 10 info?: boolean; 11 maxOutputLength?: number; 12};
Default: { level: 9 }
Compression options for algorithm
.
You can find all options here zlib.
Note
If you use custom function for the
algorithm
option, the default value is{}
.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 compressionOptions: { level: 1 }, 5 }), 6 ], 7};
threshold
Type:
1type threshold = number;
Default: 0
Only assets bigger than this size are processed. In bytes.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 threshold: 8192, 5 }), 6 ], 7};
minRatio
Type:
1type minRatio = number;
Default: 0.8
Only assets that compress better than this ratio are processed (minRatio = Compressed Size / Original Size
).
Example: you have image.png
file with 1024b size, compressed version of file has 768b size, so minRatio
equal 0.75
.
In other words assets will be processed when the Compressed Size / Original Size
value less minRatio
value.
You can use 1
value to process assets that are smaller than the original.
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
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 // Compress all assets, including files with `0` bytes size 5 // minRatio: Infinity 6 7 // Compress all assets, excluding files with `0` bytes size 8 // minRatio: Number.MAX_SAFE_INTEGER 9 10 minRatio: 0.8, 11 }), 12 ], 13};
filename
Type:
1type filename = string | ((pathdata: PathData) => string);
Default: "[path][base].gz"
The target asset filename.
string
For example we have assets/images/image.png?foo=bar#hash
:
[path]
is replaced with the directories to the original asset, included trailing /
(assets/images/
).
[file]
is replaced with the path of original asset (assets/images/image.png
).
[base]
is replaced with the base ([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, included .
(.png
).
[query]
is replaced with the query of the original asset, included ?
(?foo=bar
).
[fragment]
is replaced with the fragment (in the concept of URL it is called hash
) of the original asset (#hash
).
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 filename: "[path][base].gz", 5 }), 6 ], 7};
function
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 filename(pathData) { 5 // The `pathData` argument contains all placeholders - `path`/`name`/`ext`/etc 6 // Available properties described above, for the `String` notation 7 if (/\.svg$/.test(pathData.filename)) { 8 return "assets/svg/[path][base].gz"; 9 } 10 11 return "assets/js/[path][base].gz"; 12 }, 13 }), 14 ], 15};
deleteOriginalAssets
Type:
1type deleteOriginalAssets = 2 | boolean 3 | "keep-source-map" 4 | ((name: string) => boolean);
Default: false
Whether to delete the original assets or not.
webpack.config.js
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 deleteOriginalAssets: true, 5 }), 6 ], 7};
To exclude sourcemaps from compression:
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 exclude: /.map$/, 5 deleteOriginalAssets: "keep-source-map", 6 }), 7 ], 8};
Using a custom function:
1module.exports = { 2 plugins: [ 3 new CompressionPlugin({ 4 exclude: /.map$/, 5 deleteOriginalAssets: (name) => { 6 if (/\.js$/.test(name)) { 7 return false; 8 } 9 10 return true; 11 }, 12 }), 13 ], 14};
Prepare compressed versions of assets using zopfli
library.
Note
@gfx/zopfli
require minimum8
version ofnode
.
To begin, you'll need to install @gfx/zopfli
:
1$ npm install @gfx/zopfli --save-dev
webpack.config.js
1const zopfli = require("@gfx/zopfli"); 2 3module.exports = { 4 plugins: [ 5 new CompressionPlugin({ 6 compressionOptions: { 7 numiterations: 15, 8 }, 9 algorithm(input, compressionOptions, callback) { 10 return zopfli.gzip(input, compressionOptions, callback); 11 }, 12 }), 13 ], 14};
Brotli is a compression algorithm originally developed by Google, and offers compression superior to gzip.
Node 10.16.0 and later has native support for Brotli compression in its zlib module.
We 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:
webpack.config.js
1const zlib = require("zlib"); 2 3module.exports = { 4 plugins: [ 5 new CompressionPlugin({ 6 filename: "[path][base].br", 7 algorithm: "brotliCompress", 8 test: /\.(js|css|html|svg)$/, 9 compressionOptions: { 10 params: { 11 [zlib.constants.BROTLI_PARAM_QUALITY]: 11, 12 }, 13 }, 14 threshold: 10240, 15 minRatio: 0.8, 16 deleteOriginalAssets: false, 17 }), 18 ], 19};
Note Brotli’s BROTLI_PARAM_QUALITY
option is functionally equivalent to zlib’s level
option.
You can find all Brotli’s options in the relevant part of the zlib module documentation.
webpack.config.js
1const zlib = require("zlib"); 2 3module.exports = { 4 plugins: [ 5 new CompressionPlugin({ 6 filename: "[path][base].gz", 7 algorithm: "gzip", 8 test: /\.js$|\.css$|\.html$/, 9 threshold: 10240, 10 minRatio: 0.8, 11 }), 12 new CompressionPlugin({ 13 filename: "[path][base].br", 14 algorithm: "brotliCompress", 15 test: /\.(js|css|html|svg)$/, 16 compressionOptions: { 17 params: { 18 [zlib.constants.BROTLI_PARAM_QUALITY]: 11, 19 }, 20 }, 21 threshold: 10240, 22 minRatio: 0.8, 23 }), 24 ], 25};
Please take a moment to read our contributing guidelines if you haven't yet done so.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 21/28 approved changesets -- score normalized to 7
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More