Small Tools
Frontend utility

JavaScript Minifier

Compact JavaScript by removing ordinary comments and extra whitespace.

● This tool runs entirely in your browser. Your input is never uploaded to our servers.
Output
Your result will appear here…

How to use JavaScript Minifier

  1. Paste your JavaScript.
  2. Select Minify.
  3. Run your own tests on the result before you ship it.

Example

Input / settings:

function greet(name) {
  // Say hello
  return `Hello, ${name}!`;
}

Output:

function greet(name){return`Hello, ${name}!`;}

The comment and the whitespace around the code are removed. Text inside the template literal, including the space after the comma, is kept exactly.

When to use

Overview

JavaScript Minifier removes comments and whitespace from JavaScript with a lightweight tokenizer, not a parser. It reads strings, template literals, regular expressions and numbers as single pieces, keeps the line breaks that automatic semicolon insertion depends on, and keeps the spaces the language requires. It does not rename variables, remove unused code or check that the program is valid.

Supported input

Up to 200,000 characters of JavaScript. Modules, classes and async functions pass through as ordinary code. JSX is not supported and TypeScript annotations are kept as text.

Output details

Compact JavaScript. Comments are removed except /*! comments, and line breaks that automatic semicolon insertion depends on are kept.

Common mistakes

Practical tips

Privacy and security

This tool runs entirely in your browser. Your input is never uploaded to our servers. Minification runs locally in your browser and nothing is uploaded. Your code is only treated as text and is never run. Minified code is not obfuscated or protected, and anyone can format it again with JavaScript Beautifier.

References

Frequently asked questions

Does JavaScript Minifier rename variables or remove dead code?

No. Names and statements are written back as they were. Only comments and unneeded whitespace change.

Why did my minified code keep some line breaks?

JavaScript can end a statement at a line break when a semicolon is missing. The minifier keeps those breaks so the code means the same thing.

Can it minify modules, classes and async functions?

Yes. import and export, classes, class fields and async functions pass through like any other code. The tool does not check that they are valid.

Related tools