JavaScript Minifier for homeowners and DIYers
Homeowners and DIYers do not only build with timber and paint: many also run a small website, a page for a side job, or a simple quote form, and every one of those loads a little JavaScript. The JavaScript Minifier shrinks that script so the page loads faster on a phone, and the examples below use the kind of small scripts a home project actually has, with exact byte counts you can check yourself.
At a glance
Example 1: a menu toggle for your site, 131 bytes to 94
Most small sites have a button that opens and closes the menu on a phone. The script is short: a function that finds the menu and toggles a class called open, with one comment, 131 bytes in total. Minified, it becomes function toggleMenu(){var menu=document.getElementById(“menu”);menu.classList.toggle(“open”);} which is 94 bytes, saving 37 bytes, or 28 percent. The comment is gone, the line breaks are gone, and the spaces around the braces and the equals sign are gone. The strings “menu” and “open” are copied exactly as written, because the tool never looks inside quotes.
Why it matters: a faster page on a phone
Thirty-seven bytes sounds small, and on its own it is. But a small site often loads several scripts, and a visitor on a slow phone connection waits for every one of them. A script that is 28 percent smaller loads that much sooner, and the saving costs you nothing: paste the script, copy the result, and use the smaller copy. The tool runs in your browser, so your code is never uploaded anywhere, and there is nothing to install.
Example 2: a price script for a quote page, 252 bytes to 155
If your page works out a price — a job total with tax, say — the script is longer: a function that multiplies price by quantity, adds 20 percent tax, and prints the total, with two comments, 252 bytes in total. Minified, it is 155 bytes, saving 97 bytes, or 38 percent. The variable names subtotal and tax are unchanged, because this tool does not rename anything, and the string “Total: ” keeps its space and its colon, so the answer your customer sees is exactly the same.
How to use it on your site
Open the tool, paste your script, and press Copy minified JS. Save the result as a .js file — the Download .js button does that for you — and link it from your page with a script tag, the same way you linked the original. Keep the original file as well, in your project folder, with its comments and its spacing. When you want to change the menu or the price, change the original, minify it again, and replace the file your page loads.
The common mistake
Homeowners sometimes edit the minified file when they want to change something, because it is the file the page loads. Do not: with no comments and no line breaks, a small edit is easy to get wrong, and a wrong edit can break the menu or the price on every page. Change the original, minify it again, and put the fresh copy on the site. Minifying takes seconds, so there is never a reason to work on the packed copy.
Frequently asked questions
How much does a menu toggle script save?
From 131 bytes to 94 bytes, saving 37 bytes, or 28 percent.
Does minifying change the text my visitors see?
No. Strings are copied exactly as written, so “Total: ” keeps its space and its colon.
How much does a price script save?
From 252 bytes to 155 bytes, saving 97 bytes, or 38 percent.
Should I edit the minified file?
No. Change the original, minify it again, and replace the file your page loads.
More guides on the JavaScript Minifier
- How to use the JavaScript Minifier — step by step
- 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
Try the JavaScript Minifier — free, in your browser.