Use this free JavaScript minifier to make your code smaller. Paste your script, choose whether to keep license comments, and click Minify. The tool removes comments, extra spaces, indentation, and line breaks that are not needed, then shows the original size, the minified size, and an estimated gzip size. You can copy the result or download it as a .js file.

This tool removes comments and whitespace only. It does not rename variables or remove unused code, so it is safe and predictable, but the savings are smaller than a full build tool would give.

How to use the JavaScript minifier

  • Paste your code: add the JavaScript you want to minify to the input box.
  • Choose comments: remove every comment, or keep license comments such as /*! ... */.
  • Choose line breaks: remove them wherever it is safe, or keep one line break between lines.
  • Minify, then copy or download: click Minify, check the size saved, and copy the result or save it as a .js file.

What the minifier changes

ChangeExampleResult
Comments// noteRemoved, unless it is a kept license comment.
Spacesa = b + c;Shortened to a=b+c; and spaces needed between words stay.
Indentation and blank linesTabs and empty linesRemoved.
Line breaksreturn⏎valueKept when removing them would change the code's meaning.
Strings and regex"a b", /x +y/Left exactly as written.
Names and logicfunction total() {}Not renamed, rewritten, or removed.

Why minify JavaScript

  • Faster loading: smaller files download faster, especially on slow mobile connections.
  • Lower bandwidth: less data is sent for every visitor and every page view.
  • Cleaner delivery: production code does not need comments or formatting meant for developers.
  • Easy for small projects: a quick paste-and-copy is enough when you do not have a build step.
Keep your original, readable source file. Minified code is hard to debug, so edit the source and minify again when you make changes.

Worked examples

Remove comments and spacing

Paste function add(a, b) { return a + b; } with a comment above it. The minified result is function add(a,b){return a+b;}, and the comment is gone.

Keep a license comment

Choose Keep license comments and paste code that starts with /*! My Library v1.0 | MIT */. The license line stays on its own line at the start, and every other comment is removed.

Template literals and strings stay safe

Text inside quotes and backticks is never changed, so spaces and line breaks in your messages, HTML templates, and regular expressions are preserved exactly.

Limits to know about

  • No renaming or tree shaking: variable names stay as written, so files shrink less than with tools like Terser or esbuild.
  • No syntax check: invalid JavaScript is not fixed, and the output may be invalid too. Test the minified code before you use it.
  • Regular expressions after ) or }: a slash in that position is treated as division, which is correct in almost all code.
  • Template expressions: code inside ${ ... } is kept as written and not minified.
  • Large builds: for production apps, a bundler with minification and source maps is the better choice.

Frequently asked questions

Is this JavaScript minifier free to use?

Yes. You can minify, copy, and download without creating an account.

Is my code uploaded or stored?

No. All processing happens in your browser. Nothing you paste is sent to a server or saved, and clearing the form removes it from the screen.

Will minifying break my code?

It should not, because only comments and whitespace are removed, and line breaks stay wherever they matter. Still, always test minified code before deploying it, especially if your original code relies on unusual formatting.

Why are some line breaks still in the output?

JavaScript can treat a line break as the end of a statement. The tool keeps a line break wherever removing it might change the meaning, for example after return, after a closing brace, or before ++ and --.

Why do I get an error message?

The tool stops when it finds an unterminated string, template literal, or comment, and it shows the line where the problem starts. Fix that part of the code and try again.

What is the gzip size shown in the results?

It is an estimate of the minified file's size after gzip compression, which most web servers apply when sending files. It is shown when your browser supports compression.

Can I minify JSON or modules with this tool?

Yes for ES modules, since import and export lines are handled like any other code. For JSON, use the JSON Formatter instead, which is made for that format.

Share this article