←Work

Write-up · November 2026

24.9 MB to 780 KB

My own homepage felt slow, so I measured it. A visitor who never touched anything downloaded 24.9 MB, and 93% of it was music.

The problem

The site has a small DJ deck: press play and the page dances to ten seconds of a song. To make playback instant, the player preloaded all four songs in full on every page, one of them twice. Most visitors never press play, so every visitor paid for the few who did.

Results

Homepage download, no clicks24.9 MB780 KB
Audio downloaded on load23.2 MB0 KB
Images1.1 MB148 KB
Layout shift on a phone (CLS)0.540
Sound after pressing play (4G)instant*0.65 s (0.1 s after hover)

* Instant because all 23 MB had already downloaded. That was the trade I reversed: a short wait for the few who press play, instead of a large download for everyone.

What changed

  1. 01

    Load audio only when asked for

    The player now preloads nothing. When you press play, play() runs without waiting on anything first, because Safari only starts audio inside a user gesture. Audio on page load went from 23.2 MB to zero.

  2. 02

    Ship what actually plays

    Each press plays ten seconds from the middle of a song, so each track is now a 12-second clip cut from the middle: about 195 KB instead of 4.5–10 MB, and no seeking.

  3. 03

    Load on intent

    Hovering over the decks, or tabbing into them, starts fetching the current clip. On a throttled 4G connection, sound arrives about 0.65 s after a cold click and about 0.1 s after a hover.

  4. 04

    Right-size and self-host images

    Four album covers were 500–1400 px originals hotlinked from Deezer and Apple, displayed at 112 px at most. They are now 336 px files served from the site: 132 KB instead of 1.1 MB. It also fixed a cover that Apple’s CDN had started refusing.

  5. 05

    Let CSS decide the layout

    The hero picked its phone or desktop layout in JavaScript, which the server can’t run, so phones got the desktop layout first and then jumped. One layout arranged with CSS breakpoints took layout shift on a throttled phone from 0.54 to 0. The Strava watch now mounts once instead of twice.

  6. 06

    Don’t make people wait to read

    The bio faded in word by word, so it stayed invisible until JavaScript loaded and replayed on every return to the page. It is now in the server HTML, with a short CSS fade that plays once per visit.

How I measured

Headless Chrome driven over the DevTools Protocol, with the cache off, counting every byte in the first 15 seconds without a click. Phone numbers use 4× CPU slowdown and a throttled 4G connection, because a fast laptop hides both slow JavaScript and layout shift. Before and after each layout change, I took screenshots at four widths and compared them, so the speed-ups didn’t quietly change the design. The first version of my byte counter was itself wrong (it counted decompressed sizes), which is why I check the measuring tool before trusting any number.

Next.js · CSS · Chrome DevTools Protocol · Puppeteer

Evan Gordon