Script Valley
Web Performance Fundamentals
JavaScript PerformanceLesson 4.1

How JavaScript bundle size affects Time to Interactive

Time to Interactive, Total Blocking Time, main thread, parse and compile time, execution time, mobile CPU budget, coverage tab

JavaScript and Time to Interactive

Every kilobyte of JavaScript is more expensive than the same kilobyte of images because JS must be downloaded, parsed, compiled, and executed before the page is interactive. Images only need downloading and decoding.

On a median Android phone, 1MB of JavaScript takes roughly:

  • ~1.5s to download on a 4G connection

  • ~1.5โ€“2s to parse and compile

  • ~0.5โ€“1s to execute

Total: ~4โ€“5 seconds just for the JS, before any application logic renders content. This is why Time to Interactive (TTI) and Total Blocking Time (TBT) suffer most from large bundles.

Find unused JavaScript with the Coverage tab in DevTools (Cmd+Shift+P โ†’ Coverage):

// After opening Coverage tab and recording a page load:
// Red = unused bytes. Aim for < 20% unused on initial load.

// You can also get a programmatic overview:
performance.getEntriesByType('resource')
  .filter(r => r.initiatorType === 'script')
  .map(r => ({ name: r.name, size: r.transferSize }))
  .sort((a, b) => b.size - a.size);

The Coverage tab will show you exactly which functions in your bundle were never called during the recorded session. Those functions are candidates for code splitting or removal.

Budget recommendation: keep initial JS under 200KB (compressed) for a good TTI on median hardware. Use Bundlephobia (bundlephobia.com) before adding any npm package to check its cost.

Up next

How to code-split a JavaScript bundle with dynamic imports

Sign in to track progress

How JavaScript bundle size affects Time to Interactive โ€” JavaScript Performance โ€” Web Performance Fundamentals โ€” Script Valley โ€” Script Valley