compression-webpack-plugin

Webpack plugin that pre-compresses your build output with gzip, Brotli, or Zstandard so servers can send smaller assets via Content-Encoding.

Tool
npm
v12.0.0
1,425stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
60/100Good
Development Activity52
Maintenance36
Community64
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture82
Code Quality88
Innovation45
Learning Curve65

compression-webpack-plugin hooks into webpack’s asset-processing pipeline to generate compressed sibling files (.gz, .br, .zst, or a custom extension) for every matching build output, so a web server can serve pre-compressed assets via Content-Encoding instead of compressing them on every request. It supports Node’s built-in zlib algorithms (gzip, deflate, brotliCompress, zstdCompress) out of the box, and accepts a custom compression function for libraries like Zopfli.

Compression decisions are configurable per project: test/include/exclude filter which assets get processed, threshold skips small files, and minRatio skips files that don’t compress well enough to be worth serving twice. Results are cached through webpack’s own compilation cache keyed by content hash, so unchanged assets are not recompressed on incremental rebuilds, and deleteOriginalAssets controls whether the uncompressed originals are kept alongside the compressed ones.

What You Get

  • Built-in support for gzip, deflate, and Brotli via Node’s native zlib module, with Zstandard support on Node 22.15+
  • Pluggable custom algorithm function for other compressors (e.g. Zopfli via @gfx/zopfli)
  • Fine-grained asset filtering with test/include/exclude regex or string rules
  • threshold and minRatio options to skip files too small or too incompressible to bother with
  • Persistent, content-hash-keyed caching through webpack’s compilation cache so rebuilds don’t recompress unchanged assets
  • deleteOriginalAssets (including a keep-source-map mode) to control whether uncompressed originals remain in the output

Common Use Cases

  • Pre-gzip or pre-Brotli static assets for a CDN or Nginx gzip_static/brotli_static setup so requests skip on-the-fly compression
  • Shipping smaller JS/CSS bundles to reduce Time to First Byte for static sites and SPAs deployed to object storage
  • Serving Brotli-compressed assets to browsers that support it while leaving originals for uncompressed fallbacks
  • Producing zstd-compressed assets for internal services or edge platforms that prefer Zstandard’s speed/ratio tradeoff

Under The Hood

Architecture The plugin is a single class (src/index.js) implementing webpack’s WebpackPluginInstance contract: apply(compiler) taps compiler.hooks.thisCompilation, then registers an async processAssets hook at PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER that filters candidate assets with ModuleFilenameHelpers.matchObject, runs the configured compression algorithm, and either replaces the original asset or emits a related compressed sibling depending on deleteOriginalAssets. Compressed output is stored in a per-plugin cache obtained via compilation.getCache, keyed by a serialized options+asset descriptor and the asset’s lazy hashed etag, so unchanged inputs skip recompression entirely on incremental builds. It is a tightly scoped, single-responsibility design with one clear extension seam (a custom algorithm function) rather than a layered or pluggable architecture.

Tech Stack Plain Node.js (>=20.9) with no application framework: runtime dependencies are schema-utils for validating constructor options against a JSON schema (src/options.json) and serialize-javascript for building deterministic cache keys, with webpack as a peer dependency. The build pipeline compiles src to dist with Babel and separately emits hand-checked TypeScript declarations via tsc --declaration --emitDeclarationOnly from JSDoc annotations, with ESLint’s flat config (eslint-config-webpack), Prettier, and cspell all wired into a combined lint script.

Code Quality Testing is extensive and organized by concern: dedicated Jest suites exist per option (algorithm, compressionOptions, deleteOriginalAssets, exclude, filename, include, minRatio, test, threshold, validate-options) plus a main CompressionPlugin.test.js and snapshot fixtures, with coverage collection configured via test:coverage. Errors from the compression algorithm are pushed onto compilation.errors rather than thrown, keeping the build from crashing on a single bad asset, and all public options are typed through JSDoc generics that also drive the generated .d.ts file. CI runs lint, type-check, spelling, and tests via a GitHub Actions workflow, plus a separate dependency-review workflow, and commit messages are enforced with commitlint/husky.

What Makes It Unique The plugin doesn’t attempt anything algorithmically novel — it’s a thin, well-integrated wrapper around Node’s native zlib (and any user-supplied compressor). Its real value is in the details: webpack-native persistent caching so recompression is skipped on unchanged assets, a minRatio guard that avoids emitting compressed files bigger than a useful threshold relative to the original, and a relatedName bookkeeping scheme so downstream tooling (webpack stats, manifest plugins) can discover the compressed sibling of any given asset.

Used by 8 apps in this directory

TypeScript
68%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,825

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript68%
Java21%
Updated 3 days ago
Ruby
40%
AGPL 3.0

DocuSeal

Digital Signiture

18,446

Open source document signing platform with WYSIWYG PDF builder, multi-party workflows, REST API, and full self-hosting via Docker.

View details
87
Repo Health
80
Technical
68
Dependency
Built with
Ruby40%
Vue28%
HTML20%
Updated 1 weeks ago
Ruby
67%
Other

GitLab

Devops · Developer Tools

24,552

The complete DevOps platform that unifies Git hosting, CI/CD, issue tracking, and security scanning into a single self-hostable application.

View details
87
Repo Health
86
Technical
68
Dependency
Built with
Ruby67%
JavaScript20%
Updated today
TypeScript
61%
EPL-2.0

Huly Platform

Project Management · Team Chat · Collaboration

27,586

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
89
Repo Health
86
Technical
62
Dependency
Built with
TypeScript61%
Svelte34%
Updated 1 weeks ago
TypeScript
98%
Other

Novu

Developer Tools

39,870

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript98%
Updated yesterday
Python
58%
Other

Sentry

Security · Developer Tools · Monitoring

44,739

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
69
Dependency
Built with
Python58%
TypeScript41%
Updated yesterday
JavaScript
55%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,857

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
JavaScript55%
TypeScript38%
Updated today
Python
57%
Apache 2.0

Zulip

Team Chat

25,855

Topic-based team chat that brings the structure of email threads to real-time messaging, so distributed teams never lose context across hundreds of concurrent conversations.

View details
96
Repo Health
86
Technical
61
Dependency
Built with
Python57%
TypeScript19%
JavaScript10%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search