Skip to content

JS Minify

Minify JavaScript by removing comments and whitespace.

Input
Output

No result

About JS Minify

This minifier removes comments and collapses whitespace in JavaScript while respecting string literals and comments, so that content inside quotes is never altered. It also leaves the spacing intact around the logical operators && and ||, since collapsing those together would merge two tokens into one and change what the code does.

That last point is the whole reason a naive whitespace stripper is unsafe. Minification failures of the classic kind come from joining characters that must stay separate — turning a + + b into a ++ b, or removing the space between a keyword and an identifier. Handling operators and strings correctly is what separates a usable minifier from one that silently breaks code.

What it does not do is equally worth stating: there is no variable renaming, no dead code elimination, and no tree shaking. It reduces the size of what you wrote rather than transforming it into something smaller but less recognisable. If you need those optimisations, a build-time tool is the right place for them.

How to use JS Minify

  1. 1 Paste the JavaScript source.
  2. 2 Comments and redundant whitespace are removed, with strings and logical operators left intact.
  3. 3 Check the output before deploying — automatic semicolon insertion makes whitespace removal risky at statement boundaries.

Frequently asked questions

Does it rename my variables to single letters?

No. It removes comments and whitespace but leaves every identifier as written. Renaming requires whole-program analysis to confirm that no property access or string reference depends on the original name, which is a job for a build tool.

Why is spacing kept around some operators?

Because joining certain operators creates a different token. Two adjacent plus signs would become an increment operator, and removing the space around && or || can change how the expression is parsed. Preserving that spacing is what keeps the minified code equivalent to the original.

Is the result safe to run directly?

The tokens are preserved and only insignificant whitespace is removed, but JavaScript automatic semicolon insertion means line breaks occasionally carry meaning. Test the output before replacing working code with it — especially code that relies on ASI.

How much size does it save?

Comments and indentation are usually the bulk of the reduction, so the saving is larger on well-commented, generously formatted source. Combined with gzip or Brotli on the server, the additional gain beyond compression is modest but real.

Free, online, and private

Free to use

JS Minify is completely free. There is no account to create, no login, and no hidden charge or usage limit.

Runs online in your browser

It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.

Your data stays private

All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.

How JS Minify behaves in detail

These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.

Parameter Value
Comments recognised and removed — a `//` to end of line and a `/* … */` block are both deleted
Strings single, double and backtick literals are tracked with escapes, so a `//` inside one is not treated as a comment
Whitespace model every run becomes one space, then spaces beside { } ( ) ; , : + - * / % = < > ! & | ? are removed
Operator handling multi-character operators stay whole — `a && b` becomes `a&&b`, `x || y` becomes `x||y`, and `=>` and `??` are left intact as well
Renaming none whatsoever — the output is the input text minus comments and whitespace

Compiled from the implementation of this tool and checked against it by itoolnet.

What JS Minify does not do

Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.

  • Two adjacent unary operators are welded into one, because the space beside each punctuation character is removed independently: "a - -1" comes out as "a--1" and "a + +1" as "a++1", and the JavaScript parser rejects both.
  • The input has to be semicolon-terminated already. A line break only ever turns into a space, so automatic semicolon insertion is lost: two statements written on separate lines without semicolons are joined into a single line that will not parse.
  • Whitespace inside a string literal is collapsed by the final whitespace pass: const s = "a b"; minifies to const s="a b"; — the string value itself is changed, not just the surrounding layout.
  • Regular-expression literals get no special treatment. A whitespace run inside a pattern collapses, so /a b/ becomes /a b/ and matches different text; and if a pattern contains the two characters "/*", the scanner enters block-comment mode and everything after that point is dropped from the output.
  • It is a character scanner, not a parser: no dead-code elimination, no constant folding, no scope analysis and no identifier mangling, so the entire size change comes from comments and whitespace.

Tested and documented by itoolnet, the team that builds and maintains this site.

Share & embed this tool

Writing a guide or article? You are welcome to link to JS Minify with the snippet below. It is free, runs entirely in your browser, and needs no signup.