Skip to content
DeveloperRuns in your browser

JavaScript Minifier

Remove comments and whitespace from JS without renaming identifiers — a JavaScript minifier that keeps your names.

Input
No upload needed — instant
Privacy
Nothing is uploaded
Cost
Free · no sign-up · no watermark

Loading tool…

The tool is loading its code on your device. This happens once and is cached for later visits.

Processed entirely on your device

Everything you type or paste is handled by JavaScript running in this tab. No request is sent, nothing is logged and nothing is stored. Close the page and it is gone.

Overview

About the JavaScript Minifier

Minify JavaScript online with a conservative pass that strips comments and insignificant whitespace without renaming identifiers or altering behaviour. In-browser, no upload.

There are two things people call JavaScript minification, and it is worth being clear about which one this JavaScript minifier does. A full minifier parses your code into an abstract syntax tree, renames every local variable to a single letter, folds constants, drops unreachable branches and re-emits the smallest equivalent program. This tool does the safe half of that job: it removes comments and whitespace that cannot change what the code does, and leaves everything else exactly as you wrote it.

To minify JavaScript here is to compress it without mangling it — a JS minifier that never renames identifiers, never rewrites expressions and never touches the contents of strings, template literals or regular expressions. That makes the output predictable, greppable and safe to paste anywhere the original would have been safe.

Why a conservative JavaScript minifier is a feature

Renaming identifiers is powerful but fragile. It breaks code that reads function.name, that relies on a variable name matching a string used in reflection or dependency injection, or that shares a global with another separately minified file. A whitespace-only pass has none of those failure modes. The output is still recognisable, still debuggable and still greppable, which is exactly what you want for a snippet you are about to paste somewhere and forget.

What a JS minifier removes and what it keeps

RemovedKept
Line and block commentsAll identifiers and names
Indentation and blank linesWhitespace inside strings
Spaces around operators and punctuationNewlines inside template literals
Trailing whitespaceWhitespace inside regular expressions

The kept column is the hard part. A regular expression such as one matching a space, or a template literal spanning several lines, contains whitespace that is data rather than formatting. Stripping it would silently change behaviour, so the pass tracks those contexts and leaves them alone.

Automatic semicolon insertion

JavaScript infers semicolons from newlines in a few situations. Joining two lines carelessly can move where a statement ends and change the program. This is the classic reason a find-and-replace on newlines is not a minifier. A correct pass knows where a line break is load-bearing and keeps it, which is why the reduction is smaller than a real compiler achieves but the result is trustworthy.

When to reach for a real bundler

For an application, use Terser, esbuild or SWC in your build. They produce source maps so minified stack traces still point at your original lines, and their renaming and tree-shaking cut far more than whitespace removal can. Use this tool for the small jobs: compressing an inline script, shrinking a bookmarklet, or checking how much of a file is just formatting.

How much smaller does minified JavaScript get?

A readable, commented script usually shrinks by 20 to 40 percent with whitespace and comment removal alone. Full minifiers that also rename identifiers and drop dead code reach 50 to 70 percent, which is why production bundles go through Terser or esbuild. The gap is the price of conservatism — and for a single script, a snippet or a bookmarklet, it is a price worth paying to keep output you can still read.

Minify JavaScript you paste anywhere

Plenty of code ends up in places that punish every newline: inline event handlers, CMS script fields, bookmarklets with a length ceiling, chat messages, config-driven loaders. Those are exactly the places where a mangled, single-letter-variable bundle is a liability — you cannot debug what you cannot read. A minified-but-recognisable script compresses the formatting and keeps the meaning, so the pasted version still maps one-to-one onto the source in your editor.

What about source maps?

Source maps exist precisely because full minification destroys readability: they translate a minified stack trace back to the original lines, and every serious bundler emits them. A whitespace-and-comment pass barely needs them — the lines are the same lines, and the identifiers are the same identifiers — which is a quiet advantage when you are debugging something pasted into a console or an error reporter with no map support. If your toolchain emits maps, keep them; if you are using this tool, you will rarely miss them.

A free JavaScript minifier that keeps your names

No renaming means no failure modes: no broken function.name reflection, no dependency injection by string matching, no globals that stop matching across separately loaded files. Combined with the fact that everything runs locally — your proprietary or unreleased scripts never touch a server — this is the JS minifier for the jobs between "paste it as-is" and "wire up a bundler". Paste, minify, check the byte counts, copy or download.

Try it on a snippet you know

The fastest way to trust a conservative minifier is to feed it code you know by heart. Watch the comments vanish, the indentation flatten and every identifier survive — then check the byte counter. What you see is the entire transformation: nothing hidden, nothing rewritten, just the whitespace gone.

Step by step

How to use the JavaScript Minifier

  1. Paste your JavaScript into the input panel.

  2. Press Minify JavaScript; comments and insignificant whitespace are removed.

  3. Review the output — identifiers and logic are left exactly as written.

  4. Copy the result or download it as a .js file.

Why use it

Benefits and common use cases

What this tool is good for, and what it deliberately does not try to do.

Conservative and predictable

Only comments and whitespace that cannot change behaviour are removed. Variable names, function names and string contents are untouched, so the output is easy to reason about.

No renaming surprises

Because it never mangles identifiers, it cannot break code that relies on function.name, reflection, or names referenced across separately loaded files.

String and regex safe

Whitespace inside string literals, template literals and regular expressions is preserved, which is where a naive whitespace-stripping pass corrupts code.

Runs entirely in your tab

Proprietary or unreleased scripts are never sent to a server — the whole pass happens in the browser.

Questions

Frequently asked questions

Short, honest answers about quality, limits and privacy.

Does this rename variables like UglifyJS or Terser?

No. This is a whitespace and comment minifier, not a full compiler. It never shortens identifiers, rewrites expressions or performs dead-code elimination. That makes it safe and predictable, at the cost of a smaller reduction than a build-time bundler achieves.

Will minifying change how my script behaves?

It should not. Removing comments and insignificant whitespace does not alter semantics. The only place whitespace matters in JavaScript is inside strings, template literals and regular expressions, and those are preserved exactly.

Why does whitespace sometimes matter in JavaScript?

Automatic semicolon insertion means a newline can end a statement, so a minifier must not join two lines in a way that changes where a semicolon is implied. It also matters inside template literals, where newlines are part of the string, and in regular expressions. A conservative pass keeps those intact.

How much smaller does JavaScript get?

A readable, commented script usually shrinks by 20 to 40 percent with whitespace and comment removal alone. Full minifiers that also rename identifiers and drop dead code can reach 50 to 70 percent, which is why production builds use a real bundler.

Should I use this in production?

For a quick inline snippet or a small standalone script, yes. For an application bundle, use a build-time minifier such as Terser or esbuild that also tree-shakes, mangles names and produces source maps. This tool is best for one-off compression and for seeing exactly what whitespace removal does.