Developer Tools
JavaScript Minifier
Minify JavaScript with Terser — removes whitespace and comments, shortens variable names and drops dead code to cut file size.
How to use
- 1Paste your JavaScript (ES2020+ is supported).
- 2Choose the options and copy the minified code.
Frequently asked questions
Is minified JavaScript safe to use?
Yes. Terser is the minifier used by webpack, Vite and Next.js. Behavior is preserved as long as your code doesn't rely on function names or Function.toString().
What does 'Mangle names' do?
It renames local variables and parameters to short names like a, b, c. Global and exported names are never renamed.
Is this the same as obfuscation?
Minified code is harder to read but not protected — tools can reformat it. Never put secrets in client-side JavaScript.
Worked example: JavaScript Minifier
The 87-byte input function add(first, second) { return first + second; } (plus a leading comment and a console.log call) minifies down to function add(d,n){return d+n}console.log(add(1,2)); at 51 bytes — a 41.4% reduction. Notice add keeps its original name while the parameters first and second become d and n: Terser's mangler only renames local variables and parameters, never a function's own declared name, which matters if other code calls add(...) by that name elsewhere. Turn mangling off and drop_console on instead, and function f(){ console.log(1); return 2 } collapses to function f(){return 2} — the console.log call is removed entirely, dead-code-eliminated because its return value is never used.
Why this is the exact same engine as your build tool
This isn't a simplified reimplementation of minification — it runs Terser, the actual library webpack, Vite and Next.js use in their production builds, compiled to run in the browser via terser.minify_sync. That means the output you see here is byte-for-byte what your bundler would produce from the same input and settings, which makes this genuinely useful for understanding what your build pipeline is doing to a specific function, not just an approximation of it.
What mangling can silently break
Mangling is safe for ordinary local variables and parameters, but it breaks any code that depends on a function or variable's name being preserved as a string — Function.prototype.toString() output changes, reflection-based frameworks that look up methods by name can fail, and so can Node's class-name-based error reporting in some edge cases. The FAQ's caveat (avoid relying on function names or .toString()) is the practical rule: if your code introspects itself by name, test the minified output before shipping it, since Terser can't know your code depends on a name it would otherwise safely shorten.
Compression happens even with mangling turned off
Mangling (renaming) and compression (rewriting logic to be shorter) are separate Terser passes, and this tool always runs compression — turning off 'Mangle names' only stops the renaming, not the rest. function f(){ if (false) { console.log(1) } return 1+2; } minifies to function f(){return 3} with mangling off: the unreachable if (false) branch is deleted entirely and the constant expression 1+2 is folded to 3 at build time, neither of which touches a single variable name. Separately, var x = 1; var y = 2; merges into the single statement var x=1,y=2 — Terser combines adjacent declarations of the same kind whenever it's safe to do so, independent of any renaming setting.
Why an apparently-unused top-level function survives anyway
Paste var x = 1; function unused(){ return 99; } through the minifier and unused survives completely intact in the output, even though nothing in that snippet calls it. This isn't a missed optimization — Terser deliberately leaves top-level declarations alone by default, because it has no way to know whether unused is actually referenced from a different <script> tag, a separate module, a dynamically-constructed property lookup (window['un'+'used']), or test code that imports it. Removing genuinely-used code would be a correctness bug, so Terser only eliminates dead code it can prove is unreachable within the scope it's analyzing (like the if (false) branch above), not code that merely looks unreferenced within the pasted snippet.
Related tools
- Code Beautifier (HTML, CSS, JavaScript)
Beautify messy or minified HTML, CSS and JavaScript into clean, consistently indented code you can read and edit.
- CSS & HTML Minifier
Minify CSS or HTML to shrink file size — strips comments and whitespace and shows how many bytes you saved.
- SVG Optimizer (Minify SVG)
Shrink SVG files by removing editor metadata (Inkscape, Illustrator, Sketch), comments and whitespace, and rounding long decimals — with the size saving shown. Paste the SVG code.
- cURL to Code Converter
Convert cURL commands into JavaScript fetch, Python requests or Go net/http code — headers, JSON bodies, auth and methods included.
- Compress PDF
Shrink a PDF for email or upload. Pick light (keeps text selectable) or stronger image-based compression.
- Cookie Consent Banner Generator (GDPR-Ready Code)
Generate a lightweight, dependency-free cookie consent banner — Accept all, Reject all and per-category choices — that blocks analytics and marketing scripts until the visitor agrees. Copy-paste HTML, CSS and JavaScript.