Skip to content
ToolForge
Developer Tools

JavaScript Minifier

Minify JavaScript with terser. Mangle variable names, compress code and drop dead branches safely, with pass counts and optional ECMAScript target control. Runs in your browser.

Free, no sign-upRuns in your browserNothing uploaded

Press Minify to see the result.

input
309 B
output
0 B
saved
-
after gzip (est.)
-

The estimated compressed figure matters more than the raw one. Gzip and Brotli already squeeze whitespace and repeated tokens, so a 40% raw reduction is usually only a few percent once the file is compressed. Minify anyway, but judge it on the compressed number.

JavaScript minification does more than strip whitespace. It parses the source into an abstract syntax tree, then rewrites it: unused local variables and function parameters are removed or renamed to single characters, repeated expressions are collapsed into variables, constant conditions are evaluated so dead branches disappear, and whitespace between tokens is collapsed to the minimum the grammar allows. The result is typically 40 to 60% smaller than the source, and unlike HTML and CSS the saving survives compression far better.

This uses terser, the minifier the terser and webpack communities standardised on. Terser is conservative by design and refuses transforms that could change behaviour, which is why its output is trusted in production everywhere. It will not remove a function it cannot prove is unused, and it will not assume an identifier is global when it might be a property on the global object.

There are two things to be careful about. Mangling is safe for top-level scope only when your build already isolates modules, because renaming a global can break other scripts on the page. And minification is not obfuscation - anyone can reformat the output and read it. If you need to hide the source of client-side code, that requires a different approach entirely.

JavaScript Minifier features

Terser engine
The same minifier used by webpack, vite and the broader JavaScript ecosystem, so output matches a production build.
Variable name mangling
Local variables and parameters renamed to minimal names, with top-level control so you can keep a module's public surface intact.
Compression passes
Drop dead code, evaluate constant conditions, join sequences and fold expressions, with the pass count under your control.
Comment and license preservation
Comments are stripped by default, with the option to keep anything marked as a license comment for legal reasons.
ES target control
Compress to the ECMAScript version you need, which lets terser apply syntax-level simplifications safely for older browsers.
Source map generation
Produce a source map so production stack traces map back to readable source lines.
Browser-only processing
Parsing and minification happen in the page, so proprietary or unreleased code is never transmitted.

How to use the JavaScript Minifier

  1. Paste your JavaScript

    Type or paste, or drop a .js file onto the editor.

  2. Choose the options

    Mangle variable names, compress, drop comments, and set how many optimisation passes to run. One or two passes is usually enough; more rarely helps much.

  3. Check the output

    Raw and compressed sizes plus percentage saved. If the size barely moved, mangling is probably disabled or your code is mostly string and array data.

  4. Verify, then ship

    Load the page and exercise the code paths before deploying. Optionally generate a source map so production stack traces still point at readable source.

Frequently asked questions

Why is my minified file not much smaller?

Usually mangling is off. Without renaming locals you only remove whitespace and comments, which is 10 to 20%. If the code is mostly large string literals or data arrays, there is genuinely little to compress either, since minification does not gzip your data.

Is minification the same as obfuscation?

No, and this is a common misconception. Minification shrinks code and shortens names, but the result is trivially reformatable and readable. Anything sent to a browser can be read by the person receiving it. Obfuscation makes reading harder, not impossible, and neither is a security measure.

Can minification break my code?

Terser is conservative and breaking something usually means the code relied on something undefined behaviour, such as relying on Function.prototype.toString, on function name inference, or on an undeclared global that mangling renamed. Parse errors and syntax that depends on ASI are the other common causes. Test the minified output, not just the source.

Should I minify before or after bundling?

After. Bundle first so you get one file with resolved imports, then minify that. Minifying each module separately and concatenating breaks scoping. Vite and webpack do this for you in production mode.

How many compression passes should I use?

One or two. Each extra pass can shrink the output slightly but takes progressively longer for diminishing returns. Measure it rather than assuming; on most code the third pass changes almost nothing.

Do I need to keep the source map?

Yes, and ship it alongside the minified file. Browsers only fetch it when devtools is open, so it costs nothing at runtime, and without it every production error points at an unreadable single line.

Every tool, in one place

ToolForge has javascript minifier plus a growing set of image, colour and developer tools. All of them run locally in your browser, free and without an account.

Browse all tools