JavaScript Minifier & Beautifier
Minify JavaScript to reduce file size by 40-60%, or beautify compressed code for readability. Handles ES6+, async/await, arrow functions, template literals. 100% client side.
About JavaScript Minification
JavaScript minification removes whitespace, comments, and shortens variable names to produce the smallest possible file. This reduces bandwidth, improves page load times, and is standard practice for production deployments.
What Minification Does
- Removes all comments (single-line
//and multi-line/* */) - Removes unnecessary whitespace, newlines, and indentation
- Removes trailing semicolons where safe
- Shortens
true/falseto!0/!1
What Beautification Does
- Adds consistent indentation (2 spaces)
- Adds line breaks after statements
- Formats braces and brackets consistently
- Makes compressed code human-readable again
Related Tools
- CSS Minifier - minify and beautify CSS
- HTML Beautifier - format HTML code
- JSON Formatter - format and validate JSON
- Diff Checker - compare before/after minification
JavaScript Minification: How Much Does It Actually Save?
JavaScript minification has been a routine build step for so long that most teams ship minified code without knowing what it costs them or what they get back. The short answer: 30–60% size reduction over raw source, another 5–15% on top with mangling, and 60–80% additional on top of that with gzip/brotli. So a 100 KB source file ships as roughly 8–15 KB on the wire — most of the savings come from compression, not minification alone.
What minifiers actually do
- Whitespace removal. Strip newlines, indentation, and spaces between tokens.
- Comment removal. Drop everything except license preambles (
/*! ... */). - Identifier mangling. Rename local variables to
a,b,c. The biggest space win. - Dead code elimination. Remove unreachable branches.
- Constant folding. Pre-compute
60 * 60 * 24at build time. - Statement merging. Combine sequential expressions with commas where safe.
Production-grade minifiers (Terser, esbuild, swc) also do scope-aware analysis to mangle more aggressively without breaking semantics.
The trade-offs
- Stack traces become unreadable unless you ship source maps and your error tracker (Sentry, Rollbar) consumes them.
- Some minifiers break on ES2022+ syntax if not updated. Test in CI against the actual target browsers.
- Property mangling is unsafe by default. Renaming
obj.footoobj.abreaks anything reflecting on property names — JSON serialization, Vue reactivity, library consumers. - Minified code is harder to hash-pin in CSP. Every minifier release changes hashes; coordinate with your deploy pipeline.
When you don't need to minify
Internal tools, admin dashboards, B2B SaaS where a 200 KB extra payload is invisible — the engineering time spent debugging mangled stack traces costs more than the bandwidth. Most B2C apps and any consumer site should still minify. Modern bundlers (Vite, esbuild, Rollup) include minification with one flag.
Common pitfalls
- Minifying twice. Some pipelines minify, then ship through a CDN that minifies again, occasionally producing broken output.
- Forgetting source maps. Without them, production stack traces are useless.
- Shipping source maps publicly when the source contains IP you don't want exposed. Either don't ship them or restrict access.
- Mangling reserved properties like
$onChangesin Angular orrenderin React class components.
This minifier runs locally and is fine for one-shot reductions during debugging or quick experiments. For your actual build pipeline, use a production bundler with proper source-map support.
Frequently Asked Questions
How much smaller does minification make my bundle?
Typically 30–60% before gzip, with another 60–80% on top of that from compression. Net: 100 KB source → 8–15 KB on the wire.
What is the difference between Terser and esbuild?
Terser is more aggressive (sometimes 2–5% smaller output) but slower. esbuild is much faster and produces nearly equivalent output for most code. Most modern projects use esbuild.
Should I minify development builds?
No — debugging is much harder, and dev hot-reload depends on readable code. Minify only the production build.
Will minification break my code?
Generally no, with the exception of property-name mangling on reflected APIs. Always run your test suite against the minified bundle.