JavaScript Minifier

Minify JavaScript


          

What Is This Tool?

The JavaScript Minifier is a safe, conservative whitespace-and-comment stripper. It removes // line comments and /* */ block comments, and collapses extra blank lines and whitespace, while carefully protecting the contents of string and template literals so a // or /* inside a string is never mistaken for a comment. It does not rename variables, insert or remove semicolons, or perform any AST-level transform. Everything runs locally in your browser.

How to Use

1

Paste your JavaScript source into the input box.

2

Click Minify.

3

See the size reduction percentage.

4

Copy the result or download it as a .js file.

Features

  • Removes line and block comments
  • Protects string and template literal contents
  • Collapses extra whitespace and blank lines
  • Shows before/after size reduction
  • Copy to clipboard or download as a file
  • 100% client-side — nothing leaves your browser

Examples

Before:

// Adds two numbers together
function add(a, b) {
    /* returns the sum */
    return a + b;
}

const message = "http://example.com is not a comment";
console.log(add(2, 3));

After (minified):

function add(a, b) {
return a + b;
}
const message = "http://example.com is not a comment";
console.log(add(2, 3));

Common Use Cases

  • Quickly shrinking a small script or snippet
  • Stripping comments before sharing code publicly
  • Cleaning up whitespace from pasted or generated code
  • Reducing size of an inline <script> block

Frequently Asked Questions

Is my JavaScript uploaded anywhere?

No. Minifying happens entirely in your browser using JavaScript. Nothing is sent to a server.

Is this a real minifier like Terser?

No. This is a safe whitespace-and-comment stripper, not a real minifier. It does not rename variables, mangle scope, insert or remove semicolons, or perform any AST-level transform. For production builds, use a real minifier such as Terser, esbuild, or your bundler's built-in minification.

Will it break a `//` inside a string or URL?

No. String and template literals are extracted and protected before comment stripping runs, then restored afterward untouched, so a `//` inside a URL string is never treated as a comment.

Does it handle regular expression literals safely?

Regex literals are not specially protected, so a slash inside a regex could in rare cases be misread as the start of a comment. Review the output if your code contains complex regular expressions.

How much smaller will my code get?

It depends on how many comments and how much whitespace your original source has. The tool shows the exact percentage reduction after each run.

Can I download the result?

Yes, click Download to save the current output as a script.min.js file.