JavaScript Minifier

Minify JS with the Terser engine: comments and whitespace go, local names get shorter, and you see exactly how many bytes you saved.

Paste your JavaScript

Loading the minifier (about 1.1 MB, downloaded once)...

How to minify JavaScript with this tool

  1. Paste your code into JavaScript input, or click Open file to load a .js file. The page opens with a short example so a result shows straight away.
  2. Keep Shorten variable names ticked to rename local variables and function parameters. Keep Compress code ticked to let the minifier simplify the code itself, for example by folding constants and removing unreachable branches. Clear it to keep your statements as written.
  3. Tick Treat as ES module if the file uses import, export or top-level await. Keep Keep license comments ticked to retain comments that start with /*! or contain @license or @preserve.
  4. Read the result and the size line under the boxes, then use Copy or Download (saved as script.min.js).

How the minifying works

Minifying is done by Terser (version 5.51.2, BSD-2-Clause licence), the same engine many build tools use, running in your browser. It parses your code into a syntax tree, the way a browser would, rather than stripping spaces with search and replace. That is why strings, template literals, regular expressions and code written without semicolons all survive: the tree knows where each statement ends. The compress step then rewrites the tree, the mangle step gives local names short replacements, and the printer writes the result with only the spaces and semicolons that are needed. Sizes are counted in UTF-8 bytes, which is what a file or a download uses, and do not include gzip.

Worked example

With the default settings (shorten names on, compress on, license comments kept) the example input

// Add two numbers
function add(a, b) {
  /* simple addition */
  return a + b;
}

console.log(add(2, 3));

becomes

function add(d,n){return d+n}console.log(add(2,3));

The size line reads "106 bytes → 51 bytes (51.9% smaller)". Both comments are gone, the parameters a and b became d and n, and the top-level name add stayed because another script could call it.

Limits and edge cases

Frequently asked questions

Will minifying break my JavaScript?

Not for normal code. The minifier keeps the program's behavior and only changes how it is written. Problems come from code that relies on variable or function names, so test the minified file, and clear Shorten variable names if something misbehaves.

Can it minify JavaScript that has no semicolons?

Yes. Because the code is parsed, the minifier inserts the semicolons the language needs, so a file written in the no-semicolon style comes out valid.

How much smaller will my file get?

It depends on your code. Comments, long names and generous spacing shrink the most, while code that is already minified shrinks little or not at all. The size line shows the exact before and after in bytes.

Is minified code the same as obfuscated code?

No. Minifying makes a file smaller and happens to make it harder to read, but anyone can restore the layout with a beautifier. It does not hide what the code does, so never rely on it to protect secrets.

To read minified code again, use the JavaScript beautifier. Shrinking the rest of a page? Try the CSS minifier and the HTML minifier.

Sources: Terser 5.51.2 documentation, minify options (terser.org/docs/options).