JavaScript Minifier & Beautifier
Paste your JavaScript to minify or beautify it instantly. 100% client-side — your code never leaves your browser.
How to Use the JavaScript Minifier
- Paste your JavaScript into the input area on the left (or top on mobile).
- Choose a mode — Minify (default) compresses your JS, Beautify formats it with indentation.
- View the result instantly — the output panel updates as you type.
- Copy or download — copy to clipboard or save as output.js.
What This JavaScript Minifier Does
This free online JavaScript minifier uses a carefully designed parser to compress your JavaScript without breaking it. It handles the core challenge of JS minification: distinguishing comment-like sequences that appear inside strings and regular expressions from actual comments. The result is a compact, functional script ready for production use.
Minification Features
- Single-line comment removal — removes
// commentlines while preserving string contents - Block comment removal — strips
/* ... */comments safely - Whitespace collapse — removes unnecessary spaces, tabs, and newlines
- String preservation — content inside single-quoted, double-quoted, and template literal strings is never modified
- Operator spacing — removes redundant spaces around operators where safe
Beautify Features
- Block indentation — indents code inside
{ }blocks consistently - Statement newlines — puts each statement on its own line
- Configurable indent — choose 2-space or 4-space indentation
Why Minify JavaScript?
JavaScript files are often the largest resources on a web page and are render-blocking by default. Every extra kilobyte the browser must download before executing your scripts delays the page load. For users on mobile data connections or in regions with slower networks, this can mean the difference between a page that loads in two seconds and one that takes five or more. Google's Core Web Vitals — particularly Time to Interactive (TTI) and Total Blocking Time (TBT) — are directly influenced by JavaScript file size.
Minification reduces JS file size by removing characters that the JavaScript engine never sees anyway: comments are stripped by the tokenizer, whitespace is irrelevant to the parser, and newlines are only required where the automatic semicolon insertion rules require them. A typical unminified script of 50 KB can be reduced to 30-35 KB by minification alone. Combined with gzip or Brotli server compression, the same file might transfer as only 12-15 KB.
Limitations of Browser-Based Minification
This tool uses a string-processing approach to minification. It handles comments, strings, and template literals correctly for most real-world JavaScript. However, it does not perform advanced optimizations that dedicated tools like Terser and esbuild provide: variable name shortening, dead code elimination, inlining of constants, or module bundling. For production builds, use your framework's built-in build process (Vite, webpack, or Rollup with the appropriate plugins). This tool is ideal for quickly minifying standalone scripts, bookmarklets, or third-party code you want to embed.
JavaScript Source Maps
When minifying JavaScript for production, always generate source maps if your deployment process supports them. Source maps are separate .map files that map minified code back to the original source, making it possible to debug production errors using your original variable names and line numbers. Browser DevTools can automatically use source maps when they are linked from the minified file via a //# sourceMappingURL= comment. This tool does not generate source maps — for that, use a proper build tool. Once minified, you can compare versions using our Diff Checker.