Skip to the page

Testing a UI feature and estimating · mid

Estimating JavaScript budgets and image bandwidth

A budget comes from assumptions about the network and the phone. For slow networks, the CPU limit is tighter than the download limit. For images, the arithmetic shows how much format and size changes save.

The notes

What you must know

  • State assumptions: Lighthouse mobile preset (Slow 4G, formerly Fast 3G): about 1.6 Mbps down (about 200 KB/s), 150 ms round trip, 4x CPU slowdown, on a low-end Android phone.
  • Connection: DNS, TCP and TLS take about 3 to 4 round trips (about 0.5 to 0.6 s). HTML and critical CSS (about 50 KB) take about 0.25 s plus a round trip. So about 1 s passes before any JavaScript arrives.
  • Of a 5 s target, the remaining 4 s split into about 1.5 s of download and about 2.5 s of main-thread work (parse, compile, run, hydrate). Download limit: 1.5 s x 200 KB/s is about 300 KB compressed.
  • CPU is tighter: compressed JS grows 3 to 5 times when unpacked, and a low-end phone can need several seconds for 1 MB of raw JS. That gives about 150 to 200 KB compressed (about 600 to 800 KB raw) for the critical route.
  • Cuts: route-level code splitting, heavy libraries (date, charts, full utility libraries) out of the first load, third-party tags after interaction and server components for static parts. Enforce with a size budget in CI (size-limit or a bundle analyzer), budgets per route and RUM checks.
  • Images: 24 images on the first screen and about two screens scrolled gives about 48 images per view. Unoptimised 1200 px JPEGs at about 150 KB give 48 x 150 KB = 7.2 MB per view; 2 million views is about 14.4 TB a day, about 430 TB a month.
  • Optimised: AVIF or WebP at the displayed size (about 400 px wide, 800 px for 2x screens) at about 35 KB gives about 1.7 MB per view, about 100 TB a month, roughly 75 to 80% less. With a 95% CDN hit ratio only about 5% reaches the origin.
  • Cost is TB per month times the CDN price per GB (depends on region and volume tier), shown as a range. Use srcset and sizes, an image CDN that resizes on the fly, fetchpriority="high" only on the LCP image and blur placeholders. Smaller images also improve LCP and save mobile data.

The red pen

Common traps: mistake → fix

  • Mistake: Download size is the only budget

    Fix: parse and run time on a slow phone is tighter.

  • Mistake: Compressed and raw size are the same

    Fix: JS grows 3 to 5 times after unpacking.

  • Mistake: The CDN bill depends on origin traffic

    Fix: it is mostly edge traffic; misses cost the origin.

Easy to hard

Questions interviewers ask, easy to hard

  1. How much JavaScript can you ship for a user on a slow network in India?
  2. Estimate the CDN bandwidth for a product listing page with 24 images.
  3. How would you reduce image bandwidth by 75%?
  4. How do you keep the budget from growing again?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview