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,425 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
61 /100 Good
Development Activity 52
Maintenance 40
Community 64
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
70 /100 Good
Architecture 82
Code Quality 88
Innovation 45
Learning Curve 65

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

Automation · Developer Tools · No Code Platforms

40,959

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
TypeScript 68%
Java 21%
Updated 6 days ago
Ruby
39%
AGPL 3.0

DocuSeal

Digital Signiture

18,629

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
69
Dependency
Built with
Ruby 39%
Vue 28%
HTML 20%
Updated 1 weeks ago
Ruby
67%
Other

GitLab

Developer Tools · Devops

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
67
Dependency
Built with
Ruby 67%
JavaScript 20%
Updated 4 days ago
TypeScript
61%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,797

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

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 61%
Svelte 34%
Updated 6 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,084

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
TypeScript 98%
Updated 5 days ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

44,862

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
Python 57%
TypeScript 41%
Updated 4 days ago
JavaScript
57%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,007

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
JavaScript 57%
TypeScript 36%
Updated 4 days ago
Python
57%
Apache 2.0

Zulip

Team Chat

25,962

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
Python 57%
TypeScript 19%
JavaScript 10%
Updated 5 days ago

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