About the JavaScript Minifier
What is a JavaScript minifier?
A JavaScript minifier rewrites your code into the smallest equivalent program: whitespace and comments disappear, local variables get single-letter names, dead branches are dropped, and expressions are folded where the result can't differ. Unlike CSS or HTML, JavaScript can't be safely compressed with find-and-replace tricks — removing the wrong line break changes behavior thanks to automatic semicolon insertion. Real minification needs a real parser.
That's why this tool runs Terser, the same minifier that powers Vite, Rollup, and webpack builds everywhere — loaded locally from this site and executed in a background worker, so even large files won't freeze the page. It handles modern syntax (optional chaining, class fields, private methods, BigInt, async generators), detects ES modules automatically, keeps /*! license */ comments, and flags syntax errors with the exact line as you type. Your code never leaves the browser.
How to Use This Tool
- Add your JavaScript. Paste it into the left editor, click Open file, or hit Sample to try it.
- Choose the aggressiveness. Mangle variable names gives the biggest size win and is on by default; add Drop console.* calls for production builds.
- Check the badge. Green confirms Terser parsed and compressed your code; red shows the syntax error with its line number.
- Take the result. Copy it or download
script.min.js. The chips show exactly how much smaller it got.
Common Use Cases
- Sites without a build step: Minify hand-written scripts for landing pages, WordPress snippets, and legacy projects.
- Bookmarklets and embeds: Compress code that has to fit in a URL or a size-limited widget field.
- Shipping cleaner production code: Strip console.log noise and comments in one pass before deploying.
- Quick size estimates: See what a script would weigh minified before deciding on a bundler.
Need readable code instead? The JavaScript Formatter beautifies in the other direction, and the HTML Minifier and CSS Minifier cover the rest of your front-end assets. Or browse all our free developer tools.
Frequently Asked Questions
Will the minified code behave exactly like the original?
Yes. Terser parses your code into a syntax tree and only applies transformations proven to preserve behavior — the same guarantees your bundler relies on. Code that uses eval() is automatically treated more conservatively so scope lookups keep working.
Does it support modern JavaScript syntax?
Yes. Optional chaining, nullish coalescing, class fields and static blocks, private #members, BigInt, numeric separators, async generators, and template literals all minify correctly. ES modules are detected automatically so import and export statements are preserved.
What does "Mangle variable names" actually rename?
Local variables, function parameters, and other names that aren't visible outside their scope. Global names, exports, and object properties are never renamed, so the minified file drops into your page without any other changes.
Why is my license comment still in the output?
Comments starting with /*! or containing @license or @preserve are kept on purpose — that's the ecosystem convention for legal notices. All other comments are removed.
Can it minify TypeScript or JSX?
No — both must be compiled to plain JavaScript first, which is your build tool's job. Paste the compiled output here and it will minify fine.
Is my code uploaded anywhere?
No. Terser is served from this site and runs in a web worker inside your browser — no CDN, no server round trips, no logging. It even works offline once the page has loaded.