JavaScript minifier

Minify JavaScript with Terser in your browser: removes whitespace and comments, shortens local names and drops dead code. Keeps /*! license */ comments.

Processed locally in your browser
Loading tool…

About JavaScript minifier

The JavaScript minifier compresses code with Terser, a JavaScript parser and minifier. It removes whitespace and comments, shortens local variable and function names, and simplifies expressions and unreachable code, usually producing a much smaller file than the original.

Comments marked with /*!, @license or @preserve are kept so license notices survive. Top-level names are not renamed, so global functions and variables your page relies on keep working. Terser loads only when you use the tool and runs in a background worker; syntax errors are reported with line and column.

How to use JavaScript minifier

  1. Paste JavaScript into the input box, or open or drop a .js file.
  2. Wait a moment the first time while Terser loads, then review the minified output.
  3. Fix any syntax error reported with its line and column.
  4. Copy the result or download it as a .js file.

Features

  • Compresses with Terser’s default settings, including dead code removal and constant folding.
  • Renames local variables and function parameters; top-level names are left unchanged.
  • Keeps comments that start with ! or contain @license or @preserve.
  • Supports modern JavaScript syntax, including modules, classes and async functions.
  • Reports syntax errors with line and column.
  • Outputs the minified code only, without a source map.

Common uses

  • Shrinking a standalone script for a website without a build pipeline.
  • Minifying a bookmarklet, embed snippet or small widget script.
  • Estimating how small a script will be after minification.
  • Preparing a script to inline in an HTML page.

Tips

  • Keep the original file. Minification is one-way: local names and comments cannot be recovered, and debugging minified code without a source map is hard.

Frequently asked questions

Is the minified code safe to use in production?

Terser’s defaults are designed to preserve behavior and are used by most JavaScript build tools. Code that depends on function or class names at runtime, such as reading fn.name, can behave differently after local names are shortened. Test the minified file before deploying it.

What is the difference between minification and obfuscation?

Minification aims to make code smaller and faster to download; shorter names are a side effect. Obfuscation deliberately makes code hard to understand, for example by encoding strings or restructuring control flow. Minified code can be read again once formatted, so it does not hide secrets.

Why are my global function names not shortened?

Terser leaves top-level names unchanged by default, because other scripts or HTML attributes such as onclick may refer to them. Names declared inside functions are shortened. Wrap your code in a function if you want its internal names minified too.

Does it keep license comments?

Yes. Comments that start with !, such as /*! MIT License */, and comments containing @license or @preserve are kept in the output. All other comments are removed.

Does it generate a source map?

No. The output is the minified code only. For production builds that need source maps, run Terser or a bundler such as Vite, esbuild or webpack as part of your build.

Is my input uploaded?

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Your privacy comes first

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Find your next tool
↑ ↓ · Enter ↵Esc · Close search