A simple function
function add(a, b) { return a + b; } minifies down to function add(a,b){return a+b} with whitespace and unnecessary characters stripped.
Minify JavaScript online with Terser to shrink JS file size safely — free JS minifier.
About
Paste JavaScript and get it minified using Terser, a real parser-based minifier — the same one bundlers like webpack, rollup and vite run under the hood — so renaming variables and stripping dead code can't silently break your logic the way a naive regex-based minifier sometimes can.
Terser runs with both compression and name mangling on: it removes whitespace and comments, simplifies expressions and shortens local variable names. Top-level names are left alone by default, so global functions that other scripts call by name keep working, and comments marked /*! or @license are kept so licence notices survive.
Examples
4 worked examples
function add(a, b) { return a + b; } minifies down to function add(a,b){return a+b} with whitespace and unnecessary characters stripped.
A function with long local variable names gets those names shortened internally by Terser, while any exported names stay untouched so the code still works.
Pasting a 20KB JavaScript file and minifying it might shrink it to 8KB, with the exact percentage saved shown below the output.
function add(first, second) { var total = first + second; return total; } becomes function add(d,e){return d+e} — the local names shrink and the temporary variable disappears, but the function name stays.
FAQ
Quick answers to common questions about the JavaScript Minifier.
Paste your JS code above, make sure JavaScript is selected, then click Minify. The minified output appears in the box below it — everything runs in your browser, using Terser.
Yes. It's free, with no sign-up and no limit on how much code you minify.
It shouldn't, since Terser actually parses the code into an AST rather than blindly stripping characters — the same minifier is trusted in production by webpack, rollup and vite. Always test minified output before shipping it, as with any build step.
Yes — Terser understands modern ES module and class syntax, not just older JavaScript.
No. Minification runs entirely in your browser after Terser loads from this site — your code never leaves your device.
Yes — switch the language dropdown, or use the dedicated CSS minifier or HTML minifier page.
No. Terser shortens local variables and function parameters, but names at the top level of your script — like a global function other scripts call — are left alone, so nothing that depends on them breaks.
Yes. Use the Download button to save the result, or Copy to put it on your clipboard. A panel underneath shows the original size, the minified size and the percentage saved.
No, it produces the minified code only. If you need source maps to debug minified code in production, run Terser as part of your build tool instead.
Minifying stops and a message asks you to check the code is valid JavaScript, so no broken output is produced. Fix the error and click Minify again.
Did JavaScript Minifier work for you?