
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.
What JavaScript minification gives you
JavaScript minification removes whitespace and comments and renames symbols to shrink files before they reach the browser. This guide covers Terser setup, a Webpack production configuration, and how tree shaking complements minification. It also says when a quick pass with an online JavaScript minifier is enough for smaller scripts.
Performance impact
Figures from an e-commerce project, given as an illustration. Your results depend on your code, your dependencies and your server compression:

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 measures Core Web Vitals and uses them as page experience signals. Minification helps some of them and leaves the others unchanged:
Setting up Terser
Terser is the JavaScript minifier Webpack 5 uses by default, and the one FastMinify runs. It continues uglify-es and handles modern ES6+ syntax.
Installation
Basic configuration
Custom NPM script
A production configuration with source maps and extra passes. The unsafe options can change how code behaves; test the output before you ship it.

Configuration
Usage
Alternative with UglifyJS
UglifyJS remains a viable option, especially for older projects.
Installation
UglifyJS configuration
Webpack Integration
In production mode, Webpack 5 already minifies with Terser. The configuration below only sets the Terser options.
Configuration Webpack
package.json
Advanced techniques
Remove dead code and import only what you use, so the minifier has less to process.
Minimize the impact of polyfills on bundle size.
Before
After
Monitoring and metrics
Monitor the impact of your optimizations with these tools:

Run Lighthouse CI on every push to follow performance over time. Add assertions in a Lighthouse CI configuration file if you want the build to fail on a regression.
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
Minified JavaScript belongs in every production build. Configure Terser once, keep tree shaking in mind, and check the effect on Core Web Vitals after each release.
Related Articles

Paste a token and a JWKS to check an RS256, ES256 or HS256 signature in your browser. How kid picks the key, measured errors and the claims to check.

HTTP/2 and HTTP/3 change how files travel, not how big they are. Measured sizes, compile times and bundling tests show what minification still saves.

Convert a Unix epoch to a readable date and back, tell seconds from milliseconds, and avoid time zone, JWT and clock change traps, all in your browser.