Skip to content

JavaScript Minifier

Remove comments and unnecessary whitespace from JavaScript. Compare the original and minified code and see how many characters you saved.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is JavaScript Minifier?

This JavaScript minifier minimizes JS by removing what the JavaScript engine does not need: // and /* */ comments, indentation, blank lines and the spaces around braces, parentheses, commas and operators. The result is shown next to the original with character counts and the percentage saved.

It reads the code token by token, so strings, template literals and regular expressions are copied exactly: a URL such as "https://example.com" or a regex like /\/\/+/g is never mistaken for a comment. Line breaks are kept where JavaScript's automatic semicolon insertion depends on them, so code written without semicolons keeps working. It is ideal for bookmarklets, inline scripts and tag-manager snippets; for production bundles, build tools like esbuild or Terser also rename variables and remove dead code.

How to use JavaScript Minifier

  1. Paste your JavaScript into the Raw JS Input box.
  2. The minified code appears in the output box instantly.
  3. Check the percentage saved; if the input has an unterminated string, template or comment, the error is shown instead.
  4. Copy the minified code.

Key features

  • Removes // and /* */ comments and unnecessary whitespace
  • Keeps strings, URLs, template literals and regular expressions intact
  • Preserves line breaks needed by automatic semicolon insertion
  • Shows character counts and percentage saved
  • Reports unterminated strings, templates and comments
  • Runs entirely in your browser

Common use cases

  • Compacting bookmarklets and javascript: URLs
  • Shrinking small inline scripts and tag-manager snippets
  • Reducing the size of scripts embedded in HTML emails or JSON
  • Demonstrating what minification does when teaching
  • Quick minification without installing a build tool

Technical details & standards

The minifier tokenizes the source into words, numbers, strings, template literals (including nested ${…} expressions), regular expressions and punctuation. Whether a / starts a regular expression or a division is decided from the previous token, the same rule JavaScript parsers use. Comments are dropped, and spaces are kept only where removing them would change the code: between two words or numbers (return x, typeof y), between a + and a following + or ++ (a + +b), and in cases such as 1 .toString().

A line break is kept when the previous token can end a statement and the next can start one, which preserves automatic semicolon insertion for code like return on its own line or ++ at the start of a line. A #! shebang line is kept. Variable names are not shortened and no code is removed, so the output behaves exactly like the input; use esbuild --minify or Terser when you also want renaming and dead-code elimination.

Minimize JS from the command line

For production builds, a dedicated minifier also shortens variable names. Both commands below shrink the same small function; the output is shown under each.

Terser

npx terser app.js -c -m -o app.min.js
# function add(d,n){return d+n}console.log(add(1,2));

-c compresses (removes dead code and simplifies expressions) and -m mangles local names.

esbuild

npx esbuild app.js --minify --outfile=app.min.js
# function add(n,o){return n+o}console.log(add(1,2));

Frequently asked questions

Can minifying JavaScript break my code?

Not with this minifier's approach: it only removes comments and whitespace that the engine ignores, keeps strings and regexes byte for byte, and keeps the line breaks that automatic semicolon insertion relies on. Names and logic are not changed.

What is the difference between minification and uglification?

Minification removes whitespace and comments. Uglification (also called mangling) additionally renames variables and functions to short names. This tool minifies; Terser and esbuild do both.

How do I minify JavaScript for production?

Use your bundler's built-in minifier: Vite and esbuild (esbuild --minify), webpack (Terser) or SWC. Besides removing whitespace they rename variables, drop unused code and produce source maps for debugging.

How do I un-minify JavaScript?

Use the JavaScript Beautifier to restore indentation and line breaks. Comments removed by minification, and original names in mangled code, cannot be recovered without a source map.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More formatters & viewers tools

View all