I run a small calculator site, and one of its JavaScript files had grown to 17.8 KB. That is not huge, but it loads on every calculator page, and most of my visitors are on phones, often on slow connections. I ran it through Terser and it came out at 7.8 KB — less than half the original size. Here is what got removed.
What the file looked like before
The file is the shared script behind the calculators. It reads hours from a week table, applies the overtime rule for the visitor's state, works out the gross pay, and updates the totals on the page. Because I wrote it over many evenings, it had grown the way real code grows: long, clear variable names like overtimeHoursThisWeek, comments explaining why California treats the seventh day differently, and helper functions written for readability rather than brevity.
None of that is bad code. It is the kind of code you want when you come back to fix a wage figure six months later. But the browser does not need any of it. It needs the instructions, not the explanations.
What Terser removed first
The biggest win was the simplest one: whitespace and comments. Terser strips every comment, every blank line, and every space that is not needed to separate two tokens. My comments were generous — whole paragraphs explaining state rules — and they accounted for a surprising share of those 17.8 KB. Losing them costs nothing at runtime, because I keep the readable source and only ship the minified copy.
Next came the variable names. overtimeHoursThisWeek became something like e. regularHours, hourlyRate, grossPay — all shortened to one or two letters. Terser renames local variables and function parameters, but it leaves property names and anything the page reaches from outside the file alone. That distinction matters: if another script calls a function by name, mangling that name breaks the page. I made sure the file's public surface was small before I let Terser loose on it.
The subtler savings
The part I had not expected was how much Terser simplifies expressions. Where I had written a four-line if to work out overtime past 40 hours, the minified output uses a shorter conditional form. Constant values got folded: an expression like 40 * 1.5 became the plain number 60. Dead code went too — a helper I had stopped calling months ago, and a branch that could never run because an earlier check already covered it.
Terser also joins statements where it is safe to do so. None of this changes what the code does — only how much of it the browser has to download and parse.
What I checked before shipping it
A minified file that breaks a calculator is worse than a slow one, so I did not just upload it and hope. I kept the original file as the source of truth and generated the minified copy from it, so the two can never drift apart. Then I tested a full week on the live time card — regular hours, overtime past 40, a lunch break, and the Clear all button — and the totals matched the unminified version to the cent, on desktop and on my phone.
One thing I learned the hard way: never fix a bug by editing the minified output. The moment you do, the source and the shipped file disagree, and the next minify wipes your fix. Fix the source, regenerate, test, upload. That order is the whole workflow.
Is it worth doing?
Ten kilobytes sounds like nothing. But this file loads on every calculator page, and for a visitor on a slow mobile connection it is one less thing standing between them and an answer about their pay.
The lesson is not really about Terser. It is that the readable version of your code and the shipped version do not have to be the same file. Keep the one humans read, ship the one machines read, and make the step between them automatic. I built the calculators on mytimecardcal.com that way, and the 17.8 KB file now ships at 7.8 KB without losing a single feature.