Originally published on steirk.be.

This site scores 100 for speed, on a phone. That's nice to say, but the interesting part is how I got there. Because my first hunch was wrong, and that is exactly why I'm writing this down.

My first suspect

When the site felt slow on mobile, I went straight for the JavaScript. There was a mistake in it that I could see with my own eyes: while scrolling, dimensions were being measured and then changed right after, all mixed together. That forces the browser to recalculate every single time. Classic mistake, ugly code.

I cleaned it up. Measurements first, changes after. Result: from 0.196 to 0.152 milliseconds per frame.

An improvement of about one and a half times, on something nobody would ever have noticed.

What it really was

Only when I did a real measurement instead of going on a hunch did the truth come out.

For 1.74 seconds the page sat waiting on files that block rendering. Not my code. Google's fonts.

Those live on a different server. Your browser first has to look up that server, then set up a secure connection, then fetch a file that says where the actual fonts are, and then fetch those fonts. Only after that is any text allowed on your screen. On a good connection you barely notice. On mobile data on the train, that is your entire first impression.

I moved the fonts to my own server. The score went from 85 to 100.

All the time I had put into the JavaScript was worth ten times less than moving that one file.

Why I didn't just know that

I did know it, in theory. Everyone who builds websites knows that external fonts come at a cost.

But I had a hunch that felt better. I had seen code that was wrong, and spotting something wrong feels like finding the cause. That's the trap: you start working on what you recognise instead of on what counts.

There's only one fix for that, and it's boring. Measure before you start.

One thing I fell for

One more lesson, maybe the most useful one.

At one point I was measuring against the test server on my own laptop. That server sends files uncompressed. My stylesheet looked like 97 kilobytes there, while visitors get 21. So I was solving a problem that didn't actually exist.

Measure against the real site. Always. A measurement on your own machine tells you something about your own machine.

What I ended up doing

For those who want it concrete, in order of what it delivered:

  1. Self-host your fonts. By far the biggest effect. Make sure you don't load the same font three times: Google serves the same file under a different address for each weight.
  2. Right-sized images. A photo 1600 pixels wide in a 340 pixel box isn't just slow to download, it's also slow to decode. For the logos on this site, even 212 kilobytes turned out to come down to 36.
  3. Turn off heavy effects on small screens. A rotating gradient with blur looks gorgeous and costs a phone more than you'd think.
  4. Only then the JavaScript. That mistake was real, but it was fourth in line.

And then the honest part

Speed isn't a goal in itself. Nobody picks you because your site scores 100.

But slowness does cost you clients, especially the visitors you don't know yet and who have no reason to wait yet. And the best part: almost everything above is one-off work. You do it right while building, and after that it stays right.

Wondering whether your site suffers from this? Send me the address, and I'll measure it and tell you honestly what I see.