JS Minifier & Beautifier

Compress JavaScript for production or format minified code for readability — with VS Code syntax highlighting and instant byte savings.

Share this tool
VS Code syntax highlighting
Preserves license comments
Load example:

Processing JavaScript...

Paste your JavaScript above and click Minify or Beautify.

What JavaScript Minification Removes

Removed

  • • Single-line comments //
  • • Block comments /* ... */ (except /*! ... */)
  • • Newlines, tabs, and redundant spaces
  • • Trailing semicolons before }
  • • Leading zeros: 0.5 → .5

Preserved

  • • /*! ... */ license and preserved comments
  • • String content inside " ", ' ', and template literals
  • • Whitespace inside string literals
  • • All semantic tokens — identifiers, operators, keywords
  • • Regular expressions and their flags

What Is JavaScript Minification?

JavaScript minification removes characters that the interpreter ignores — whitespace, newlines, tabs, and comments — without changing what the code does. The JavaScript engine executes minified code identically to formatted code; the only difference is fewer bytes traveling over the network.

Real-world minification typically saves 50–70% of the original file size, depending on how heavily commented and indented the source is. A library with JSDoc comments for every function and generous spacing can compress more than two-thirds. Already-compact code saves less.

Build tools — Webpack, Vite, Rollup, and esbuild — minify JavaScript automatically as part of their production output. This tool is useful when working outside a bundler, when you receive a third-party script you want to re-serve, or when you need to quickly inspect how much a specific file can shrink.

JavaScript Beautifier — When to Use It

The beautifier does the reverse — it takes minified or poorly-formatted JavaScript and adds 2-space indentation, line breaks after { and }, and a blank line between top-level declarations. The output is semantically identical but formatted for human readability.

Use the beautifier when you need to:

  • • Debug a minified vendor script — read its logic without staring at one long line.
  • • Review a pull request where minified JS was accidentally committed instead of source.
  • • Inspect a CDN-hosted library to understand an undocumented API.
  • • Onboard onto a legacy project that ships raw minified files with no build pipeline.

Real-World Minification Savings

LibraryOriginalMinifiedSavings
jQuery 3.7.1284 KB92 KB~68%
Lodash 4.17.21544 KB72 KB~87%
Hand-written utility lib~8 KB~3 KB~62%
React 18 (dev build)Use production build — already minified by React team—

Minification, Bundling, and Tree-shaking

These three are separate, complementary optimisations — each operates at a different level:

  • Minification removes whitespace, comments, and redundant characters from existing code. It does not change the logic or remove any functions. This tool does minification.
  • Bundling combines multiple .js files into one (or a few) output files. Fewer HTTP requests can improve load time, especially without HTTP/2. Webpack, Vite, and Rollup all bundle as part of their pipeline.
  • Tree-shaking removes exported functions and variables that are never imported elsewhere. It requires ES module syntax (import / export) so the bundler can statically analyse what is used. A 500 KB utility library where you only use two functions can be reduced to a few KB.

In production: bundle first, tree-shake during bundling, then minify the output. All three together produce the smallest possible file that your application actually needs.

Frequently Asked Questions

Is minified JavaScript valid JavaScript?
Yes. Browsers, Node.js, and every other JavaScript engine execute minified code identically to formatted code. Whitespace and comments carry no semantic meaning in JavaScript; removing them does not change any function, variable, or control flow.
Will minification break my code?
Not with this tool. The minifier is conservative — it only removes whitespace and comments, strips trailing semicolons before }, and shortens 0.5 to .5. String literals, template literals, and all identifier names are preserved exactly. It does not rename variables or rewrite logic.
Can I keep license comments during minification?
Yes. Use /*! ... */ — note the exclamation mark immediately after the opening /*. Preserved comments survive minification verbatim. This convention is honored by this tool, UglifyJS, Terser, and most production JavaScript minifiers.
What is the difference between minify and uglify?
Both terms describe removing whitespace and comments, but "uglify" (from the tool UglifyJS) additionally renames local variables, function parameters, and internal identifiers to single-letter names like a, b, c. This extra step — called mangle — typically saves another 10–30% on top of whitespace removal. This tool does not mangle names; it preserves all identifiers.
Should I minify JavaScript in development?
No. Keep your source JavaScript readable during development — browser DevTools, source maps, and error stack traces all depend on line numbers and identifier names. Minification belongs exclusively in your production build pipeline. Your build tool (Webpack, Vite, esbuild) handles this automatically when you run a production build.
Can I reverse minification and get the original source back?
Not completely. The Beautify mode restores readable indentation and line breaks, but the original variable names, comments, and formatting decisions cannot be recovered once they are removed — the information is permanently discarded. Source maps (generated at build time alongside the minified file) are the correct tool for mapping minified code back to its original source in DevTools.

Related Tools