JavaScript Minifier

Minify JavaScript with Terser.

About the JavaScript Minifier

Terser 5.49.0 in your browser: paste JavaScript, press Minify, read the result. Nothing is uploaded or run: Terser parses your code and prints it back smaller. It runs Terser's default compress and mangle with every comment removed; there is no options panel. Terser began in 2018 as a fork of uglify-es, the abandoned ES2015+ branch of UglifyJS, and is the minifier webpack runs by default; here it minifies the one-off script or inline snippet that never meets a bundler.

How to use the JavaScript Minifier

  1. Paste your JavaScript into the input panel, or press Sample to load an example.
  2. Press Minify. Terser parses the whole file first, so a syntax error stops here with the parser's message under the input.
  3. Read the output: comments gone, local names shortened, top-level names exactly as you wrote them.
  4. Copy the result, or Download it as script.min.js.

Frequently asked questions

What do Terser's compress and mangle do by default?
Compress folds what it can prove and drops what cannot run. 24 * 60 * 60 becomes 86400, an if that returns true or false becomes the bare comparison, true and false become !0 and !1, and statements are joined with commas; unreachable branches, code after a return, unused local variables and debugger statements are removed. Mangle renames function parameters and local variables to a letter or two. console.log calls and unused parameters stay, and ES5 input comes out as ES5: Terser's default ecma setting never introduces syntax newer than the code you pasted.
Which names are renamed, and which are left alone?
Renamed: function parameters, local variables, functions and classes declared inside another function, and private class fields such as #count. Left alone: every top-level declaration, even in a file with import and export, because the page runs Terser with toplevel off and another script may reference them; property names and object keys, since property mangling is off; the contents of string literals; and anything in a scope that calls eval, which Terser skips entirely. Code that reads names at runtime is the one thing that breaks: an inner function's .name comes back shortened, and a dependency injector that inspects parameter names sees the short ones.
Does Terser remove comments?
Here, all of them. The page passes format.comments: false, so line comments, block comments, //# sourceMappingURL lines, and the /*! banners and @license or @preserve notices that Terser's own default setting keeps are all gone. If a license header has to ship with the file, paste it back in front of the output. A file that is only comments minifies to nothing, and the page reports that instead of showing an empty result.
What does "Unexpected token: punc" mean?
Terser's parser met punctuation where the grammar allows none, and the message names the token. punc (}) is a stray or unmatched closing brace, punc ()) an extra closing parenthesis, punc (,) a doubled comma in an object literal, and punc (:) is usually pasted JSON or a TypeScript type annotation, since neither is JavaScript. JSX and HTML fail as operator (<), because < is an operator to a JavaScript parser. When the parser knows what it wanted it says so, as in Unexpected token punc «{», expected punc «)» for an if condition missing its closing parenthesis. Terser minifies plain JavaScript only, so compile TypeScript or JSX first and minify the output. The message appears under the input; search the input for the token it names.
Which JavaScript syntax does it parse?
Current JavaScript. Verified on this page: optional chaining, nullish coalescing and the ??=, ||= and &&= assignments, BigInt literals with numeric separators, class fields, private methods and static blocks, optional catch bindings, import.meta, regular expressions with the v flag, and import attributes such as with { type: "json" }. import and export statements are kept. Two things are rejected: decorators, which stop at Unexpected character '@', and top-level await, because the page parses input as a classic script rather than a module; wrap it in an async function to minify it here.
Is this a Terser playground or REPL?
It is Terser running in your browser tab, the version named above: paste JavaScript, press Minify, then copy or download the output. It is not a REPL, since your code is parsed and rewritten, never run. There is no options panel: the settings are the defaults described above with comments removed, and they cannot be changed here. For a specific compress or mangle option, run Terser from its command line.
Is minifying the same as obfuscating?
No. Terser makes code smaller, not secret. Strings survive verbatim, so an API key in a string literal is exactly as readable after minifying as before; property names, object keys and every top-level name survive too; and the renamed locals are plain JavaScript that the JavaScript Formatter re-indents in one click. There is no string encoding, control-flow flattening or self-defending code, which is what an obfuscator adds. Never treat minified output as protection for a secret.
Is my source uploaded?
No. Terser is JavaScript itself and runs inside the page; there is no backend.

Related tools