JavaScript Minifier

This JavaScript minifier removes comments and extra whitespace from your code. It reads the source token by token first. So strings, template literals and regular expressions come through intact. The tool never renames a variable. Your output behaves exactly like your input.

Your files never leave this device

Minify your JavaScript Safe · Nothing is renamed

What this is and is not: a whitespace and comment minifier, not a compiler. It does not rename variables, remove dead code or transpile syntax, so the savings are smaller than a build tool achieves, and nothing can break.

Comments

Many open-source licences require the notice to survive minification.

How to minify JavaScript

  1. Paste your JavaScript into the box above.
  2. Tick Keep license banners if your code carries one.
  3. Read the minified output that appears right away.
  4. Check the saving in characters and as a percent.
  5. Copy the result or download it.

What this JavaScript minifier gives you

  • Token based reading so a comment marker inside a string stays safe.
  • Correct detection of a regex literal versus a division sign.
  • Template literals kept byte for byte with their whitespace.
  • Line breaks kept where automatic semicolons depend on them.
  • No renaming so stack traces still make sense.
  • An option to keep license banners that open source terms require.

Why JavaScript is harder to minify than CSS

CSS has few traps. JavaScript has several. Each one lets a careless minifier produce code that looks fine and then fails when it runs.

The classic trap is the forward slash. In a / b it means division. In /ab+/g it starts a regular expression. The tool must know what came before to tell them apart. A minifier that guesses wrong will delete half a pattern.

Strings cause the same trouble. Take "https://example.com" as an example. The two slashes are not a comment. A simple pattern based minifier treats them as one and cuts the line short. This tool reads tokens first and avoids that.

Automatic semicolon insertion

JavaScript adds semicolons where it thinks you meant one. Its rules depend on line breaks. Remove the line break after a bare return and the function may return something different. The same risk applies after throw, break and continue. It also applies after a postfix increment.

This minifier keeps a line break wherever its removal could change meaning. That costs a few bytes. It also removes a whole class of bugs that are painful to trace in production.

What this JavaScript minifier does not do

FeatureBuild toolsThis tool
Remove comments and whitespaceYesYes
Rename variablesYesNo
Remove dead codeYesNo
Tree shakingYesNo
Transpile modern syntaxOftenNo

The result is a smaller saving. Expect 20 to 40 percent and not the 60 or 70 a bundler reaches. In return nothing can break. Use a real build tool for a full app. Use this tool for a snippet or an inline script. It also fits code you want smaller without a build step.

Why the tool never renames anything

A rename breaks code that relies on names at run time. Dependency injection by parameter name breaks. Reflection over function names breaks. Error messages lose their meaning. Bugs get hard to trace without a source map.

This tool keeps every name. So a stack trace from the minified file still points at code you recognize. The output also stays readable enough to audit. That matters when you minify code someone else wrote.

Where the real savings come from

Minification is rarely the biggest lever for file size. Remove libraries you no longer use. Load scripts only on pages that need them. Turn on gzip or brotli on your server. Those steps often save more than any minifier.

A safe JavaScript minifier workflow

  1. Keep your readable script as the source file.
  2. Make every edit in that source.
  3. Minify a copy right before you upload it.
  4. Test the page with the minified copy in place.
  5. Name the output clearly such as app.min.js.

A clear name tells teammates which file to edit. The next upload would wipe changes made to the wrong copy.

Common JavaScript minifier problems

My code stopped working after I minified it

Check that you copied the full output. Then check the source for a syntax error. The tool keeps meaning but cannot fix broken code.

The saving looks small

Your code has few comments or was already compact. A rename step would save more but this tool skips it on purpose.

My license banner disappeared

Tick the option to keep license banners. Banners start with /*! in most libraries.

Who uses a JavaScript minifier?

Web developers shrink inline scripts. WordPress users trim custom snippets. Email and landing page builders cut file size. Students see how minified code looks.

Your code stays private

The tool works in your browser and uploads nothing. Private code stays on your machine. Need to shrink other files too? Try the CSS minifier, the HTML minifier or the JSON minifier. Want to test a pattern first? The regex tester helps.

Frequently asked questions

Does the JavaScript minifier rename my variables?

No. A rename step saves the most bytes but it breaks code that relies on names. It also makes stack traces hard to read.

How much size will I save?

Usually 20 to 40 percent. Heavily commented code saves more. A build tool with renaming saves more still.

Will it break my regular expressions?

No. The tool reads tokens first. It tells a regex apart from a division sign and keeps the pattern exactly.

What about automatic semicolons?

The tool keeps line breaks where their removal could change meaning. That covers return and throw. It also covers break and continue.

Should I use this instead of a build tool?

Not for a full app. Use a real bundler there. This tool suits snippets and inline scripts.

Does the tool upload my code?

No. Your browser does all the work. Your code stays on your device.