Developer Tools

JavaScript Minifier

Remove comments and redundant whitespace from JavaScript without renaming anything, so behaviour is guaranteed unchanged.

Free to use No registration Mobile friendly Unlimited usage

What is the JavaScript Minifier?

There are two kinds of JavaScript minification, and the difference matters more than the name suggests.

The aggressive kind rewrites your code. Variables are renamed to single letters, dead branches are removed, functions are inlined, and the output bears little resemblance to the input. Tools like Terser and esbuild do this, and the size reduction is dramatic - often 60% or more.

The conservative kind only removes characters that never mattered: comments and unnecessary whitespace. Every identifier keeps its name. Every statement stays where it was. The saving is smaller, usually 20% to 35%, but the behaviour is guaranteed identical.

This tool does the second kind, deliberately.

Why the conservative approach

Renaming variables is safe only if the tool can see every reference to them. That assumption breaks in ways that are easy to miss. Code that calls a function by name from an HTML attribute. A library that reads Function.prototype.toString. Anything using eval. Dependency injection frameworks that inspect parameter names. Web components registered by string. In each case the renamer changes something that another part of the system was looking for by name, and the failure appears at runtime rather than at build time.

For a script you are pasting into a page footer, a snippet going into a tag manager, or a small file you are uploading by hand, that risk is not worth taking for an extra 20%. If you have a proper build pipeline with tests, use a proper minifier there.

Strings and regular expressions are protected

The hard part of minifying JavaScript is knowing when a character means what it appears to mean. A // inside a string is not a comment. A / might start a regular expression or might be division. An apostrophe inside a double-quoted string is just an apostrophe.

This tool scans character by character, tracking whether it is inside a string, a template literal or a comment, and only removes what is genuinely removable. String and template contents are set aside during whitespace collapsing and restored afterwards, so the spaces inside your messages survive exactly as written.

What it removes

Comments, both // line comments and /* */ block comments. Note that this includes licence headers, which some libraries require you to keep - check before minifying third-party code.

Whitespace: indentation, blank lines, and the spaces around operators and punctuation.

What it does not touch: your variable names, your function names, your structure, or your semicolons. Automatic semicolon insertion has caused enough grief over the years that removing them is not a risk worth taking.

Benefits of using the JavaScript Minifier

Behaviour cannot change

Nothing is renamed and nothing is restructured, so code that reflects on function names or is called from HTML keeps working.

String-aware scanning

A <code>//</code> inside a string is not treated as a comment, and regular expressions are not mistaken for division.

Right for snippets

Ideal for footer scripts, tag manager code and hand-uploaded files where there is no build step and no test suite.

Honest about the trade-off

Expect 20% to 35% rather than the 60% an aggressive minifier claims - the difference is the risk you are not taking.

How to use the tool

Step 1

Paste your JavaScript

Step 2

Keep remove comments on unless you need to preserve a licence header

Step 3

Keep collapse whitespace on for the size reduction

Step 4

Press Minify JavaScript and check the before and after sizes

Step 5

Test the result before deploying it

Popular use cases

  • Footer scripts and inline snippets
  • Google Tag Manager custom code
  • Hand-uploaded static files
  • Email and landing page scripts
  • WordPress theme scripts
  • Removing comments before publishing
  • Quick size checks
  • Code without a build pipeline

Frequently asked questions

Because this one does not rename anything. Aggressive minifiers get their headline figures by shortening every identifier to a letter or two, which is where most of their saving comes from. Skipping that costs size and buys certainty that nothing breaks.

No. JavaScript's automatic semicolon insertion has well-known edge cases where omitting one changes what the code does, and the byte saved is not worth that risk. Every semicolon you wrote stays.

Ready to start using TU Web Tools?

Free, browser based utilities for developers, SEO professionals, students and businesses.

Free to use  •  Mobile friendly  •  No installation required