Format Code Now
/
Web & markupJavaScript Minifier Next: PHP Beautifier ›

JavaScript Minifier

WM-76

Paste JavaScript to remove its comments and extra whitespace, and see how many bytes you saved. The code is checked first, and the output is checked again.

Runs in your browser. Nothing is uploaded.

JavaScript

Minified JavaScript

How to use it

  1. Paste your JavaScript into the input box, or open a .js file.
  2. Leave Keep /*! and @license comments ticked if your code carries a license header.
  3. Click Minify JS, or Size saved to see the byte counts.
  4. Copy the result or download it as a .js file.

What it removes

It removes comments and the spaces and line breaks the language does not need, and writes the code tight: x=a+b instead of x = a + b. Strings, template literals and regular expressions are copied exactly. Where a line break might matter, for example between statements written without semicolons, it is kept, so the output is not always a single line. Comments that start with /*! or contain @license or @preserve are kept unless you untick the box.

What it does not do

This is a whitespace and comment minifier, not a full optimizer. It does not rename variables, shorten property names, remove unused code or rewrite expressions, so files shrink less than with a tool that does those things. It reads JavaScript only, not TypeScript or JSX. If you need the smallest possible bundle, use a build-step tool; this is for quick shrinking of a snippet or a script.

The safety checks

The input is parsed as JavaScript before anything happens, so a syntax error is reported with its line and column instead of producing broken output. After minifying, the result is parsed again. If it does not parse, no output is shown and you get a message instead of code that might fail. The minifier is our own, so test the result before shipping it.

Error messages and what to do

MessageWhat it meansFix
Invalid JavaScript: Unexpected token, expected ")" at line 1, column 7The input is not valid JavaScript at that point.Fix the syntax near the position shown, then minify again.
Invalid JavaScript: Unterminated template. at line 1, column 12A template literal opened with a backtick has no closing backtick.Add the closing backtick.

Questions people ask

How do I minify JavaScript online?

Paste the code and click Minify JS. Comments and unneeded whitespace are removed, and the result is checked to make sure it still parses. Copy it or download it as a .js file. Click Size saved to see before and after byte counts.

Does it rename my variables?

No. Names stay as you wrote them, so the output is readable but larger than what a full minifier produces. Only comments and whitespace are removed. If you need mangling, use a build-step tool such as a bundler with a minify setting.

Will minifying break my code?

It is designed not to. A line break is kept where removing it could change the meaning, strings and regular expressions are untouched, and the output is parsed again as a check. Still, test minified code before you ship it, as with any minifier.

Why is my output on several lines?

Line breaks are kept where automatic semicolon insertion could change the meaning, such as after a closing brace or between statements without semicolons. Add semicolons to your source and more of the code joins onto one line.

Does it keep license comments?

Yes, by default. Block comments that start with /*! or mention @license or @preserve are kept on their own line at the position they were in. Untick the box to remove them as well.

Can it minify TypeScript or JSX?

No. It parses plain JavaScript, so type annotations or JSX tags give a syntax error. Compile TypeScript or JSX to JavaScript first, then minify the output.

About this tool

This is a whitespace and comment minifier, not a full optimizer. It removes comments and unneeded spaces and line breaks, and keeps a line break wherever removing it could change how the code is read, so the result is not always a single line. It does not rename variables, shorten property names, remove unused code or rewrite expressions, so files shrink less than with a tool that does. Before and after, the code is parsed as JavaScript; invalid input is reported with its line and column, and if the output would not parse no output is given. It reads JavaScript only, not TypeScript or JSX. Strings, template literals and regular expressions are left as written.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.