How to use the JavaScript Minifier — step by step
A JavaScript file you write for people to read is full of things a browser does not need: comments that explain the code, blank lines that separate ideas, and spaces that make lines easy to scan. The JavaScript Minifier removes those extras and hands back the same code in a smaller form. Open the tool and it already shows an example: a short greet function of 93 bytes that minifies to 61 bytes, saving 32 bytes, or 34 percent. Nothing is uploaded anywhere — the work happens in your browser — and the five steps below take you from pasting code to using the smaller result.
At a glance
Step 1: paste your JavaScript
Click in the box labelled Your JavaScript, delete the sample if you do not need it, and paste your own code. There is no file upload and no size box to fill in: the tool minifies as you type, so the result updates with every keystroke. If you paste a whole file, paste the whole file; if you paste one function, paste one function. The box accepts any ordinary JavaScript, from a three-line helper to a full page script.
Step 2: read the three numbers
Above the output box, the tool shows how much smaller the code became. For the sample it reads 34% smaller, with two lines underneath: Original: 93 characters · Minified: 61 characters, and Saved: 32 characters. Those three numbers are the whole result: the first is what you pasted, the second is what you will use, and the third is the difference. When the saved number is small, your code was already tight; when it is large, comments and blank lines were doing the heavy lifting.
Step 3: see what was removed
The tool removes two kinds of text and shrinks a third. It deletes comments, both the // line comments and the /* */ block comments. It collapses every run of spaces, tabs and new lines into a single space. And it removes the spaces around the punctuation {} ( ) ; , : and =, which the browser never needed. What it does not touch is just as important: text inside quotes is copied exactly as written, so the space inside “Hello, ” stays, and the spaces around + and - are kept, because removing them can change what the code means.
Step 4: copy or download the result
Press Copy minified JS to put the smaller code on your clipboard, then paste it where it belongs: a script tag, a .js file, or your site builder. If you would rather have a file, press Download .js and the tool saves the minified code as minified.js. Either way, keep your original file as well — the minified copy is for use, not for editing, because nobody wants to read code with no spaces and no comments.
Step 5: test the minified code
Before you put minified code on a live page, run it once. Paste it into your browser console, or load the page and click through what the code does. The sample should still greet the world: greet(“World”) still calls the function, and the function still returns “Hello, World”. A quick test takes a minute and catches the one case this tool cannot handle, which is a regular expression written as a literal with repeated spaces inside it.
Worked example
Here is the sample the tool opens with, before and after. The original is 93 bytes, the minified version is 61 bytes, and the saving is 32 bytes.
function greet(name) {
// say hello
return "Hello, " + name;
}
/* done */
greet("World");
function greet(name){return "Hello, " + name;}greet("World");Both comments are gone, the spaces around the braces, the parentheses and the equals sign are gone, and the space inside the string “Hello, ” stays, because it is part of the text. The spaces around the + also stay, because the tool keeps them on purpose: a - -b is not the same as a--b, so spaces around + and - are never removed.
The common mistake
People paste their code, copy the result, and never run it. That works almost every time, because comments and whitespace are safe to remove. The time it fails is when the code contains a regular expression written directly, such as /a b/, with two spaces between the letters. The tool treats that as ordinary code and collapses the two spaces to one, giving /a b/, which matches something different. Strings in quotes are safe — “keep my spaces” comes out unchanged — but a bare regular expression is not a string, so check your code for one before you minify.
Frequently asked questions
How do I use the JavaScript Minifier?
Paste your JavaScript in the box, read the bytes saved, press Copy minified JS, and test the result once before you use it on a live page.
How much does the sample shrink?
The sample goes from 93 bytes to 61 bytes, saving 32 bytes, or 34 percent.
Does the minifier change my strings?
No. Text inside quotes is copied exactly as written, so the space inside “Hello, ” stays.
Why are spaces around + kept?
Because removing them can change meaning: a - -b is not the same as a--b, so the tool never removes spaces around + and -.
More guides on the JavaScript Minifier
- JavaScript Minifier explained with worked examples
- JavaScript Minifier formula — how it actually works
- JavaScript Minifier for beginners — start here
- Common mistakes people make with the JavaScript Minifier
- JavaScript Minifier vs doing it by hand — which is faster?
- JavaScript Minifier — the complete guide
- How to get an accurate result from the JavaScript Minifier
- JavaScript Minifier for students — with examples
- JavaScript Minifier for homeowners and DIYers
Try the JavaScript Minifier — free, in your browser.