Skip to content

Developer Tools

JS Minifier

Shrink a script with the Terser engine, right in your browser. Choose whitespace-and-comments-only for the safest result, or full mode to also shorten local variable names.

  • Free
  • No sign-up
  • Runs in your browser

Guide

What this JavaScript minifier does

This tool runs Terser, a widely used JavaScript minifier, directly in your browser. It actually parses your code, so it knows the difference between a string, a regular expression, a comment and real code, which simple whitespace strippers get wrong.

There are two modes. Whitespace and comments only removes comments and unneeded spacing and puts everything on one line, but keeps every variable and function name as written. Full also shortens local variable names, merges declarations and simplifies expressions for the smallest result. Names that other code might call, such as top-level functions, are kept in both modes.

When it is handy

It suits quick jobs: shrinking a snippet for a bookmarklet, fitting code into a place with a length limit, preparing a small inline script, or seeing how much of a script is comments and spacing. The size before and after, and the percentage saved, are shown above the result.

For a whole project, use the same kind of minification in your build tool so it runs automatically on every release. If you are working with styles instead, the CSS Minifier does the equivalent job, and for data the JSON Minifier is exact.

How to use it

  1. Paste your JavaScript into the box labeled JavaScript. A small function with a comment is already there.
  2. Pick a mode: whitespace and comments only, or full.
  3. The Minified box updates a moment after you stop typing. Click Copy to copy the result.

If your code has a syntax error, the tool shows the message with the line and column instead of output, which also makes it a quick syntax check. Your code is processed in the browser and is never uploaded. The Terser engine downloads the first time you use this tool, so the first result can take a second.

What is kept intact and what to check

Because the code is parsed, strings keep their spaces, regular expressions are not mangled, and code that relies on automatic semicolon insertion gets proper semicolons added instead of breaking.

Things to keep in mind: the tool handles modern JavaScript syntax but not TypeScript or JSX, so compile those first. In full mode, anything that depends on a function's name or on reading a variable name from a string (such as eval or code that inspects Function.name) can behave differently. In every case, run the minified code before relying on it, and keep your readable source as the file you edit.

Frequently asked questions

Does it rename variables like a production minifier?

In Full mode, yes: local variables are shortened and code is simplified. In the safe mode, only comments and whitespace are removed and all names stay the same.

Will it break my strings or regular expressions?

No. The code is parsed properly, so text inside strings, template literals and regular expressions is left exactly as written.

Will it tell me if my JavaScript has errors?

Yes. A syntax error is shown with its line and column instead of output. It does not run your code or find logic mistakes.

Does it work with TypeScript or JSX?

No. Paste plain JavaScript. Compile TypeScript or JSX first.

Is my code sent to a server?

No. It is processed locally in your browser.