JavaScript Minifier

Minify JS for production or beautify for readability.

JavaScript Minifier β€” What It Does

Paste JavaScript code to strip whitespace, comments, and unnecessary characters for a production-ready minified output. Or paste minified code to beautify it back into readable, indented format. Both operations run entirely in your browser β€” no code is sent to any server. Useful for optimising inline scripts, inspecting third-party snippets, or quickly preparing code for deployment.

What Minification Removes

  • Whitespace and newlines β€” Indentation and blank lines serve humans, not the JS engine
  • Comments β€” Both // single-line and /* block */ comments are stripped
  • Optional semicolons β€” Removed where ASI (Automatic Semicolon Insertion) makes them redundant
  • Variable name shortening β€” Long names replaced with single letters in advanced mode

Minification vs Build Tools

  • This tool β€” Best for quick one-off minification, inspecting output, or minifying standalone scripts
  • esbuild β€” Fastest build-time minifier for bundled projects; used internally by Vite
  • Terser β€” Most advanced JS minifier with aggressive dead-code elimination; used by webpack
  • Rollup β€” Ideal for library builds; produces clean, tree-shaken ESM output

Tips for Safe Minification

  • Always test minified output β€” Run your test suite on the minified bundle before deploying to production.
  • Generate source maps β€” Source maps let DevTools map minified code back to original lines for debugging. Build tools generate these automatically.
  • Preserve licence comments β€” Some libraries require retaining /*! ... */ licence comment blocks in the minified output.

Frequently Asked Questions

What does JavaScript minification actually do to the code?
Minification removes all characters that are unnecessary for execution: whitespace, newlines, comments, and optional semicolons. Advanced minifiers also shorten variable names (a, b, c instead of userAccountDetails), collapse constant expressions, and remove dead code branches. The result is functionally identical but much smaller.
How much file size reduction should I expect from minification?
For typical JavaScript files with comments and readable formatting, minification reduces file size by 20–50%. When combined with gzip compression (which web servers apply automatically), the effective saving is often 60–80% compared to the original uncompressed, unminified source.
What is the difference between minification and obfuscation?
Minification optimises for file size by removing unnecessary characters. Obfuscation deliberately transforms code to make it hard to read and reverse-engineer β€” using nonsensical variable names, encrypting string literals, and adding confusing control flow. Minification is a routine production step; obfuscation is used when source code protection matters.
Should I minify JavaScript manually or use a build tool?
For production projects, use a build tool like webpack, Vite, Rollup, or esbuild β€” they handle minification automatically as part of the bundle step, along with tree-shaking, code splitting, and source maps. Manual minification via this tool is useful for quick one-off tasks, third-party snippets, or checking minified output.
Can I un-minify or beautify minified JavaScript to read it?
Yes β€” the beautify mode in this tool reformats minified JavaScript with consistent indentation and line breaks, making it readable. Note that variable names shortened by the original minifier cannot be recovered. For debugging minified production code, use browser DevTools source maps if available.