
Compress and minify JavaScript safely
Minifying JavaScript removes everything a browser doesn't need to run it, like comments, indentation, and line breaks, so your pages download faster. This compressor offers two levels. Safe mode strips comments and whitespace without touching a single piece of your actual code, then checks its own work. Maximum mode uses Terser, the minifier behind most modern build tools, to also shorten variable names and simplify expressions for the smallest possible file.
Everything runs in your browser. Your code is never uploaded.
How to use it
- Paste your code, or open one or more
.js,.mjs, or.cjsfiles. You can also drag files onto the tool. - Choose Safe or Maximum mode, and adjust the options.
- The minified code updates automatically. Check the size savings and the verification badge.
- Copy the result or download it as
.min.js. Several files at once download together as a ZIP.
Why most online JS compressors break code
Many quick compressors use simple find-and-replace rules to delete anything that looks like a comment or extra space. JavaScript is too tricky for that. A // inside a string or URL isn't a comment, a / can start a regular expression or mean division, and code without semicolons depends on line breaks to run correctly. Get any of these wrong and the "compressed" file throws errors or, worse, quietly behaves differently.
Safe mode reads your code the way a JavaScript engine does, token by token, so it always knows whether it's looking at a string, a template literal, a regular expression, or real code. It keeps a line break wherever removing one could change how the code runs:
let count = total
++attempts // this line break must stay, or ++ binds to "total"
return
value // and this one too: "return" ends the statement hereAfter minifying, the tool reads its own output again and compares every token with your original. The green Verified badge means the two are identical except for comments and spacing. Before release, this minifier was tested on the complete TypeScript compiler (over 1.3 million tokens), React, marked, and pdf-lib. Each minified library was run and produced exactly the same results as the original.
Safe vs. Maximum
| Safe | Maximum (Terser) | |
|---|---|---|
| Removes comments and whitespace | Yes | Yes |
| Shortens variable names | No | Yes, local names only unless you choose top-level too |
| Simplifies code (dead code, constant folding) | No | Yes |
| Typical size reduction | 20 to 55% on commented, formatted code | 40 to 75% |
| Output is readable | Mostly. Names and structure are unchanged | No |
| Risk | Essentially none, and verified | Very low, but code that relies on function names or eval can be affected |
What about gzip and Brotli?
Web servers usually compress files again with gzip or Brotli before sending them. That's why the tool shows the gzip size too, which is roughly what your visitors actually download. Minifying and gzip work together: minifying removes text a browser never needs, and gzip squeezes the repeated patterns in what's left. If your server doesn't compress files automatically, download the pre-compressed .min.js.gz version and configure the server to send it with Content-Encoding: gzip.
Keeping license comments
Open-source licenses such as MIT usually require keeping the copyright notice. Comments that start with /*! or contain @license or @preserve are kept by default. That's the same convention every major minifier follows.
Frequently asked questions
Is my code uploaded anywhere?
No. Both modes run entirely in your browser. Maximum mode downloads the open-source Terser engine from a public code CDN the first time you use it, but your code itself never leaves your computer.
Can I minify JSX or TypeScript?
Not directly. JSX and TypeScript need to be compiled to plain JavaScript first, usually by your build tool. Minify the compiled output.
Will minified code still work with source maps?
The tool doesn't generate a new source map, so an existing sourceMappingURL comment is removed by default, since it would point to a map that no longer matches. Keep it only if you'll regenerate the map yourself.
Why is my already-minified file barely smaller?
Files that are already minified have no comments or extra whitespace left to remove. Maximum mode may still find a few percent, and gzip will give the biggest additional saving.
Is "Remove console.* calls" safe?
Usually. It deletes console.log, console.warn, and similar calls, which is common for production builds. Leave it off if your code passes values through console calls or depends on their side effects.
How big a file can it handle?
Safe mode handled the 8.9 MB TypeScript compiler in about a second during testing. Minifying happens in a background thread, so the page stays responsive either way.
