My Music Player Cost 70 MB Before Anyone Pressed Play

Performance/10.Nov.2026/5 min read
#performance#build-log#frontend#third-party
All Articles
TL;DR

I put a music player on my portfolio and it was costing every visitor about 70 MB of memory before they clicked. I fixed it by loading on approach and unmounting on close. Update, 25 Nov: the default track is now a local MP3, not a YouTube embed.

The yellow dot sits near the bottom of my portfolio. You scroll past it, maybe you click it, and a small record player slides out with a song. I rebuilt that card more times than I'll admit: rounded corners, a progress bar, a pen icon.

Then I opened Chrome's task manager. The player was holding about 70 MB of tab memory, and most of it was charged before anyone clicked. Every visitor. Every phone. Every old laptop. For a feature most would never open.

This pattern is everywhere now. A chat bubble in the corner. A map on a contact page. A payment form in a checkout. You add one line of HTML, and a company you'll never meet starts running an app inside your page. My music player just made the bill visible.

The first fix took two changes. Only one was about writing less code. Both apply to any embed you don't control.

Nobody opened it, and everybody paid

Version one mounted the player on page load. Simple. The card is hidden, the browser handles the rest.

Version two was cleverer: load on first interaction, or eight seconds after load. Then I watched what counts as interaction. A mouse move or a scroll counts. Eight seconds isn't long.

Almost everyone still paid. I optimized the code I could see and ignored the black box I couldn't. The player is about 1,400 lines, but JavaScript is cheap next to what it creates.

The hidden part was a whole second app

Inside the player was a hidden YouTube iframe. In the browser it's a separate browsing context, often a separate renderer process, with the other company's scripts, caches, and timers inside it. The comment in the file says tens of megabytes, plus about 900 KB of third-party scripts. A chat widget or a map is the same deal, just quieter.

So why would hiding a box keep a video player alive? Because display: none changes pixels, not processes. The iframe is still mounted, still connected, still holding what it downloaded.

Lazy, for real, means the component doesn't exist. Not invisible. Gone.

Load on approach, not on click

A click is too late to start loading. By the time the pointer reaches the dot, I want the player warm. So the trigger is proximity: within 220 pixels, start quietly in the background. Most never come close. The ones who do get a card that opens without a spinner.

Touch screens have no hover, so that signal doesn't exist. There I warm up when the dot scrolls into view, at 60 percent visibility. Never scroll that far, never pay.

components/notch-player-lazy.tsx The Trigger
const PROXIMITY_PX = 220
const UNUSED_RELEASE_MS = 45_000
const CLOSED_RELEASE_MS = 30_000

function nearTrigger(x: number, y: number) {
  const el = document.querySelector("[data-notch-trigger]")
  if (!el) return false
  const r = el.getBoundingClientRect()
  const dx = Math.max(r.left - x, 0, x - r.right)
  const dy = Math.max(r.top - y, 0, y - r.bottom)
  return Math.hypot(dx, dy) <= PROXIMITY_PX
}

// Armed but never opened: release after 45 seconds.
// Used and closed: release after 30 seconds and drop the iframe.
const delay = wasOpen ? CLOSED_RELEASE_MS : UNUSED_RELEASE_MS
window.setTimeout(() => setArmed(false), delay)

That last timer is the one that matters. Closing the card used to stop the audio and leave the process running. Now it unmounts 30 seconds later, which drops the iframe and everything it brought with it. Reopening costs a fresh boot. That was the trade I wanted.

Update, 25 November

Two weeks later I cut that to 1 second. It hides the reboot and frees the iframe faster.

The bigger change was the default track. It also came from YouTube. I put one MP3 in the public folder: 3.4 MB at 128 kbps, the full song. That sounds like a downgrade next to a 900 KB script, until you count what it starts. A file is fetched once and decoded. An embed boots a player, a process, and code I can't inspect or shrink.

Pasted YouTube links still use the embed, because there I have no choice. The default track, the one almost everyone hears, makes no third-party request at all.

How to check your own page

Same approach as when the whole page felt slow: measure, name the cost, remove it.

Open Chrome's task manager (Shift+Esc on Windows, Window menu on a Mac), load your page, and touch nothing. Write the number down. Open the widget you suspect, close it, wait. If memory stays high, it's still mounted. Try it with the CPU throttled too.

Chrome doesn't always hand memory back at once, so expect noise. Direction is what matters.

If the embed is optional, mount it on intent and release it on close. If it's the point of the page, keep it, but know what you're paying. The worst case is the one in the middle: a widget nobody uses, loaded for everyone.

The Takeaway
  • Every iframe you didn't write is an app you're hosting. Budget for it.
  • Lazy means unmounted. Hidden still runs.
  • Load on intent, release on close, host the asset when you can.