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
How to use the JavaScript Minifier
Paste your JavaScript
Type or paste, or drop a .js file onto the editor.
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.
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.
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?
Is minification the same as obfuscation?
Can minification break my code?
Should I minify before or after bundling?
How many compression passes should I use?
Do I need to keep the source map?
Related tools
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