MSMuhammad Shahid

Free tool · runs in your browser

JavaScript minifier

Make your JavaScript smaller by removing whitespace and comments, shortening names and simplifying code.

Powered by Terser. Your code is parsed and rewritten in your browser, and is never run or uploaded.

Quick answer

Paste your JavaScript to minify it with Terser, the same engine used by many build tools. It removes comments and whitespace, shortens local variable names and simplifies code, and shows the bytes saved. Modern syntax is supported. Syntax errors are reported with their line and column. Your code is never run or uploaded, as it is only parsed in your browser.

How to use it

  1. Paste your JavaScript. It is minified a moment after you stop typing.
  2. Choose the options. Shorten names, simplify code or keep licence comments.
  3. Copy the result. Test it before you ship it, and keep your original for editing.

Example

The top-level name stays. The local names and whitespace go:

Input

function add(first, second) {
  // adds two numbers
  const total = first + second;
  return total;
}

Output

function add(n,d){return n+d}

Common errors and how to fix them

Syntax error
The code cannot be parsed. Fix the error at the line and column shown, and check for missing brackets.
Unexpected token: import or export
This tool minifies classic scripts. Use a bundler for module code.
My code stopped working after minifying
Code may depend on function or variable names. Turn off "Shorten local variable names" and test again.

Frequently asked questions

What does minifying JavaScript do?

It removes comments and whitespace, renames local variables to short names, and rewrites code into shorter equivalents, so it downloads faster and behaves the same.

Can minified code be reversed?

Partly. Formatting tools can restore the layout, but the original names and comments are gone. It is not a security measure.

Will minifying break my code?

Rarely. Issues come mostly from code relying on function names or on eval. Turn off "Shorten local variable names" if you suspect that.

Does it shorten global names?

No. Top-level names can be used by other scripts, so they are kept. That is why top-level functions keep their names.

What is the difference between minifying and obfuscating?

Minifying aims to reduce size. Obfuscating aims to make code hard to read and often makes it larger.

Does it support ES6 and modules?

Yes, for modern syntax including arrow functions, classes and async/await. Code using import or export needs a module build, so use a bundler for those.

Should I minify by hand or use a bundler?

Use a bundler such as Vite or webpack for real projects, as they run minifiers automatically. This tool is for single scripts and quick tasks.

Is my code executed or stored?

No. It is only parsed and rewritten as text in your browser.

Should I minify CSS as well?

Yes, it is usually a quick win for page speed. Use the CSS minifier.

Does minifying hide my code or secrets?

No. Anyone can still read it, so never put API keys in browser code. To store a fingerprint of a value rather than the value, see the hash generator.

Sources

Related

More tools in this group

Guides and apps