JavaScript Minifier

Strip the comments and layout out of a script, without renaming a single thing inside it.

Runs on your deviceDeveloperWorkingNo account needed

What this tool does

JavaScript Minifier reads your source character by character and removes what a browser never needed: // line comments, /* … */ blocks, the indentation at the front of every line and the blank lines between them. Quoted strings, template literals and regular expressions are recognised as they go past and copied through byte for byte, so a // sequence inside a URL string survives, and a template spanning three lines keeps all three.

What it does not do is the part worth reading first. Identifier renaming, dead-code removal and constant folding — the passes that make an uglify or terser build genuinely small — are all missing here, and two lines of code are never welded into one. That restraint is deliberate: a newline in JavaScript can be doing the work of a semicolon, and deleting one in front of a line that opens with a bracket quietly changes what the code means. So every line that carries code stays its own line, every name you chose survives, and the saving is comments and layout alone — substantial on a documented, four-space-indented file, close to nothing on one that arrived compact.

That makes this the wrong tool for a production bundle. A build step running esbuild, terser or Rollup will cut far more than this leaves, emit a source map so stack traces still point at real lines, and resolve your imports; none of that happens here. It earns its place where there is no build step to reach for — a snippet pasted into a template, a theme file edited in production, a script kept in a repository as one plain file — or when you want a smaller version you can still read and diff against the original.

Everything happens inside this browser tab. Paste the script, press Run, and nothing is uploaded; the page keeps working with the network off, which matters when the file names an internal endpoint or an unreleased feature. Two limits follow from scanning the source instead of parsing it. Whether a slash opens a regular expression or divides two numbers is judged from the character before it, not from any understanding of the expression. And JSX and TypeScript are not understood at all: a // in JSX text is read as a comment and takes the remainder of that line with it, while type annotations simply travel through, so TypeScript in is TypeScript out. Ordinary JavaScript is covered by the tool's own tests; anything unusual deserves a glance at the output before it ships.

How to use it

  1. Paste the script. Drop it into the JavaScript box, or press Load sample to see how a comment, a regular expression and a string containing // are each treated.
  2. Decide what the comments are worth. Keep /*! and @license comments is on by default, and @preserve counts as well, because stripping the banner a licence obliges you to carry is not a saving worth taking. Switch it off and every comment goes, banners included.
  3. Leave space collapsing on, or turn it off. Collapse runs of spaces and tabs squeezes padding used to align code — a column of assignments, say — down to a single space. Turn it off to keep that alignment intact; the indentation at the start of each line goes either way.
  4. Read the saving, then copy the result. Under the output box sit the before and after sizes in UTF-8 bytes and the percentage the pass removed, counted on the file you pasted. Copy output then puts the minified script on the clipboard; nothing is offered as a file.

Processing & privacy

Runs on your device. Your file is processed directly in this browser.

Common use cases

A snippet going straight into a page

Inline script in a template or a tag manager has no build behind it, so every note you wrote while developing is downloaded by every visitor until something removes it.

A theme or plugin file edited in place

Scripts shipped inside a WordPress theme are deployed as they are. Dropping the comment blocks and indentation shrinks them while leaving the function names you will need to read again next month.

A third-party file vendored into a repository

Keep the licence banner, lose the several hundred lines of API documentation above the code, and the file stays legal to redistribute and quicker to scan.

Measuring what a file is made of

Run it once and the before and after figures tell you what share of the source was comments and layout, which is a fair argument for or against adding a real build step.

Questions

Is my code uploaded anywhere?
No. The whole pass is JavaScript running in this tab, so the source is neither transmitted nor kept, and the tool carries on working after you disconnect — worth having when the file holds an endpoint, a key or something not yet public.
Does it rename variables the way uglify does?
No. Nothing is renamed, no branch is dropped and no expression is folded. Those passes need a real parser and scope analysis behind them. This removes comments and layout, which is why the result is still readable and still diffs sensibly against your source.
Why is the output not one long line?
Because joining lines is where a whitespace-level minifier breaks working code. Automatic semicolon insertion means a line break sometimes ends a statement, and removing it changes the meaning of whatever follows. Leaving each line of code where you put it costs a handful of bytes and removes that entire class of bug.
What sort of saving should I expect?
It depends on how heavily commented and indented the source was: a documented library loses a great deal, a file already written tightly loses very little. The figures shown are the real before and after on your own input, in UTF-8 bytes, rather than an average quoted from somewhere else.
Will it damage my regular expressions?
Recognised ones are copied through untouched, and the tool's tests cover division and escaped slashes. Recognition is the caveat — a slash is read as the start of a pattern or as division based on what precedes it, not on a full parse — so check the output if your code puts a regular expression somewhere unusual.
Where else can the scanner lose its place?
Two cases are worth knowing. A template literal nested inside another template's ${…} is mispaired, and the indentation held inside the inner one can be stripped, which changes the string. A /* with no matching */ takes everything after it, because the scan runs to the end of the file looking for the closing marker. Both are visible in the output pane if you read it.
Does this replace a bundler?
No. esbuild, terser and Rollup rename identifiers, remove unreachable code, bundle modules and write a source map. Use one of those where you have a build to hook into, and this where you do not.
Can I get the original back afterwards?
Not from here. The comments are gone for good and this tool does not re-indent, so treat the output as a build product and keep editing the file you started with.

Related tools