
JavaScript Minification Guide — Terser and Webpack
How JS minification works: Terser setup, Webpack production config, tree-shaking notes, and when an online minifier is enough.
Why minify your JavaScript?
JavaScript minification removes whitespace and renames symbols to shrink file size before it reaches the browser. This guide covers Terser setup, Webpack production configuration, and how tree shaking complements minification — plus when a quick pass with an online JavaScript minifier is enough for smaller scripts.
Real-world performance impact
Here are real optimization data from an e-commerce project:

Before optimization
- File size
- 2.3 MB
- Load time
- 3.2s
- Bounce rate
- 68%
- Conversion rate
- 2.1%
After optimization
- File size
- 580 KB
- Load time
- 1.8s
- Bounce rate
- 42%
- Conversion rate
- 3.7%
Google uses Core Web Vitals as a ranking factor. Minification directly improves these metrics:
Setting up Terser
Terser is UglifyJS's successor, faster with better ES6+ support.
Installation
Basic configuration
Custom NPM script
Optimal configuration for production environment with source maps and advanced optimizations.

Configuration
Usage
Alternative with UglifyJS
UglifyJS remains a viable option, especially for older projects.
Installation
UglifyJS configuration
Webpack Integration
Professional integration in a modern Webpack workflow.
Configuration Webpack
package.json
Advanced techniques
Eliminate dead code and optimize imports for maximum minification.
Minimize the impact of polyfills on bundle size.
Before
After
Monitoring and metrics
Monitor the impact of your optimizations with these tools:

Set up alerts to maintain performance.
Configuration GitHub Actions
Try our free minification tools to optimize your code:
JavaScript Minifier
Minify, unminify and beautify your JavaScript code instantly.
CSS Minifier
Optimize your CSS stylesheets for better performance.
JSON Formatter
Format minified JSON with customizable indentation — dedicated JSON tools cluster.
SVG Optimizer (SVGO)
Deep SVGO optimization beyond quick minify — safe, default and aggressive presets.
Prepare strings for URLs, markup, or API payloads — everything stays in the browser:
Base64
Encode or decode UTF-8 text as Base64, including URL-safe alphabet.
URL encode
Percent-encode query components or full URIs with encodeURIComponent, encodeURI, or form scopes.
URL decode
Decode percent-encoded query strings and URLs — component, full URI, or form-urlencoded.
HTML entities
Escape or unescape &, <, quotes, and named entities before inserting into markup.
Conclusion
JavaScript minification isn't an option, it's a necessity. With the right practices and tools, you can significantly reduce your file sizes while improving user experience and SEO.
Related Articles

Stages, includes, `rules:`: structurally validate a .gitlab-ci.yml before the pipeline runs — not a GitLab runner, not official CI Lint.

Broken YAML, missing `on` or `jobs`, empty steps: structurally validate workflows before you push — and keep actionlint in CI.

SDL syntax errors, schema review and formatting before merge — extends the existing GraphQL beautifier.