JavaScript Minifier

Strip comments and whitespace from JavaScript safely. Nothing is renamed and broken output is never returned.

JavaScript

This removes comments and whitespace. It does not rename variables or drop dead code, because doing that correctly needs a full parser and a mistake means broken production code.

Minified

How to Minify JavaScript

1

Paste your code

A single file or a snippet. Strings, template literals, regular expressions and comments are all recognised, so nothing inside them is touched.

2

Read the size difference

Comments and indentation are usually a third of a source file. The before and after bytes are shown with the percentage saved.

3

Copy the result

The output is compiled before you ever see it. If it did not parse, you get your original back instead of something broken.

Features

Removes comments and unnecessary whitespace
Strings, template literals and regular expressions left untouched
Automatic semicolon insertion respected, so newlines that matter survive
Licence comments starting with /*! kept by default
Output compiled before it is shown, so broken code is never returned
Tells you when the problem is your input rather than the minifier
Typically 30 to 40 percent smaller on unminified source
Free and runs in your browser

Frequently Asked Questions

Because renaming safely needs a full parser and a scope analysis, and getting it slightly wrong produces code that looks fine and breaks in production. A tool that removes comments and whitespace correctly is more useful than one that mangles names and is right most of the time. For the full treatment, run esbuild or terser in your build.

Usually 30 to 40 percent on ordinary unminified source, and it depends almost entirely on how heavily commented the file is. A real minifier with renaming gets to 50 or 60 percent, and gzip on top of either matters more than the difference between them.

The output is compiled before you see it, so it cannot hand you something that fails to parse. What no syntax check can prove is that the meaning is unchanged, which is why the tool avoids every transformation where that is in doubt. Test the result, as you would with any build step.

Because JavaScript inserts semicolons at line ends in specific places, so removing a newline can change what the code means. After return, throw, break, continue and yield, and before ++ or --, the newline is part of the language and is kept.

Not as part of a build: your bundler already does it better. This is for the cases where there is no build, like a snippet going into a CMS field, an inline script in an email template, or a quick look at how much of a file is comments.

Yes. Optional chaining, nullish coalescing, class fields, private names, template literals, generators and async functions all tokenize correctly. It has been tested against real source files and the output re-imported to confirm it still loads.

You get told that the input is broken rather than the output. The input is checked first precisely so a pre-existing error in your file does not look like a bug in the minifier.

Yes, with our CSS minifier and HTML formatter. Both take the same care with strings and URLs that this one takes with regular expressions.

Need a Custom Tool or Application?

We build production-grade web applications, SaaS platforms, and developer tools. Let's talk about your project.

or book a free call