← All blog posts

JavaScript Minifier — the complete guide

WhiteUI · A plain-English guide to the JavaScript Minifier

Minifying is a small job with a surprising number of details: two kinds of comment, three kinds of string, a list of punctuation whose spaces go, and two operators whose spaces stay. This guide covers every part of the JavaScript Minifier: what it removes, what it keeps, the limits, and the everyday uses, so you never have to guess what a setting does — there are no settings, only the rules below.

At a glance

Price script: 155 bytes0 bytes126 bytes252 bytes252 → 155 bytes, 97 saved (38%)
A price script minifies from 252 bytes to 155 bytes, saving 97 bytes, or 38 percent.

What the tool removes

Three things go. First, comments: // line comments to the end of the line, and /* */ block comments even across several lines. Second, line breaks and indentation: every run of spaces, tabs and new lines becomes a single space, so five lines become one. Third, the spaces around the punctuation {} ( ) ; , : and =, which the browser never needed. In the default sample, those three removals take a 93-byte function down to 61 bytes, saving 32 bytes, or 34 percent.

What the tool keeps

Three things stay. First, every string: text inside double quotes, single quotes and backticks is copied exactly as written, so “Hello, ” keeps its trailing space and “Total: ” keeps its space after the colon. Second, the spaces around + and -, because removing them can change meaning: a - -b is not the same as a--b. Third, every name in your code: subtotal stays subtotal and tax stays tax, because this tool does not rename anything. The price script shows all three at once: it minifies from 252 bytes to 155 bytes, and the names and the strings are still there in full.

Strings and template literals

Quoted strings are the one part of your code the tool never looks inside. A template literal is copied whole, including the ${name} inside the backticks, and an ordinary string keeps every space, even a double space. Try this example, 111 bytes with a comment: it minifies to 77 bytes, saving 34 bytes, or 31 percent, and the template literal is unchanged.

const msg = `Hello, ${name}!`;
// welcome the visitor
const shout = (text) => {
  return text.toUpperCase();
};

const msg=`Hello, ${name}!`;const shout=(text)=>{return text.toUpperCase();};

The comment is gone, the spaces around the equals signs are gone, and the line breaks are gone. The backtick string, the ${name} inside it, and the arrow function all survive exactly as written.

Operators: the spaces that stay

The tool keeps the spaces around + and - and around * and / as well, because none of those are in its punctuation list. Return n * 2 stays return n * 2, and a + b stays a + b. Only the spaces around {} ( ) ; , : and = are removed. A short test makes it plain: var a = 5; var b = 3; var c = a - -b; goes from 37 bytes to 29 bytes, saving 8 bytes, and the spaces around the minus signs are still there in the result, because a - -b with the spaces removed would mean something else entirely.

Copying and downloading the result

Press Copy minified JS to put the smaller code on your clipboard, then paste it into a script tag, a .js file, or your site builder. Press Download .js and the tool saves it as minified.js instead. The tool runs entirely in your browser: nothing is uploaded, stored or logged, so your code never leaves your own computer. There is no account, no cost and nothing to install, and the result updates as you type, so every keystroke gives you a fresh answer.

The common mistake

People paste code that depends on its comments, such as a commented-out line they meant to keep as a note, or a warning written as a comment at the top of the file. Comments are removed, always, so those notes vanish from the minified copy. Keep notes in your original file, which you should keep anyway, and never rely on a comment surviving into the version your website loads.

Frequently asked questions

What does the JavaScript Minifier remove?

Comments, line breaks and indentation, and the spaces around {} ( ) ; , : and =. The default sample goes from 93 bytes to 61 bytes.

What does it keep?

Strings in quotes, the spaces around + and -, and every variable name. subtotal stays subtotal and “Hello, ” keeps its trailing space.

Does it work with template literals?

Yes. A template literal is copied whole, including ${name} inside the backticks, and arrow functions minify normally.

Is my code sent anywhere?

No. Everything runs in your browser. Nothing is uploaded, stored or logged.

How much does a longer script save?

A 252-byte price script saves 97 bytes, or 38 percent, minifying to 155 bytes.

More guides on the JavaScript Minifier

Try it yourself

Try the JavaScript Minifier — free, in your browser.

Open the JavaScript Minifier