JavaScript Minifier

Shrink JavaScript safely, strings, regex and template literals left untouched.

Paste JavaScript to minify it.


Result will appear here.

, Original
, Minified
, Saved

This performs conservative, lexer-based minification: comments and redundant whitespace are removed, but nothing is renamed or restructured. A production bundler such as esbuild or Terser will do considerably better because it can shorten local variable names and remove unreachable code, transformations that need a full parser and are not safe to attempt here.

Features

  • Removes line and block comments
  • Collapses redundant whitespace
  • Preserves strings, template literals and regex literals exactly
  • Byte savings report
  • Never renames identifiers, so behaviour cannot change

How to use it

  1. Paste your JavaScript into the input box.
  2. Choose which cleanups to apply.
  3. Press Minify.
  4. Copy or download the result.

Why naive JavaScript minification breaks code

Stripping comments with a regular expression is the classic mistake. The sequence // appears inside URLs in strings, and /* can appear inside a regex literal. A naive comment-stripper turns const url = 'https://example.com' into const url = 'https: and breaks the file. This minifier walks the source character by character, tracking whether it is inside a string, template literal, regex or comment, which is the only reliable way to tell them apart.

Distinguishing a regex literal from a division operator is genuinely ambiguous without parsing. In a / b / c the slashes are division; in a = /b/g they delimit a regex. The lexer here uses the standard heuristic of looking at the previous significant token, after an identifier, number or closing bracket a slash is division; otherwise it starts a regex. That is correct for essentially all real code.

Automatic semicolon insertion is why the keep-semicolons option defaults to on. JavaScript will insert semicolons at line breaks under certain rules, so removing newlines from code that relies on ASI changes its meaning. A line starting with ( or [ is the classic hazard, it gets attached to the previous line as a call or index. Keeping semicolons and only collapsing whitespace avoids the whole category of problem.

Frequently asked questions

Yes, completely. JavaScript Minifier is free with no usage limits, no account and no sign-up. There is no paid tier and no trial that expires. Tools marked Premium on this site carry that label to indicate a deeper feature set, not a price.
JavaScript Minifier covers removes line and block comments, collapses redundant whitespace, preserves strings, template literals and regex literals exactly, among other things. Everything is available immediately with no account, no sign-up and no usage limit.
Stripping comments with a regular expression is the classic mistake. The sequence // appears inside URLs in strings, and /* can appear inside a regex literal. A naive comment-stripper turns const url = 'https://example.com' into const url = 'https: and breaks the file. This minifier walks the source character by character, tracking whether it is inside a string, template literal, regex or comment, which is the only reliable way to tell them apart.
Everything is processed in your browser. Code, tokens and payloads you paste in never leave your device, which matters when you are debugging something that contains real credentials or customer data. Check the Network tab if you want to confirm it. Because nothing depends on a server, the tool also keeps working offline once the page has loaded, the site registers a service worker that caches it after your first visit.

Related tools

Further reading

📖 JavaScript Minification: Smaller Bundles, Faster Load Times

Read the full guide on the 123MiniApps blog.

Pick a theme

Ten hand-tuned palettes.