Bundle Size Impact of Code Splitting
You'll learn how React.lazy() reduces initial bundle size and when code splitting actually delivers value.
The Core Problem
Without code splitting, your entire app ships as one JavaScript bundle. A user visiting your homepage downloads everything—the admin panel, settings pages, chart libraries—even code they'll never use in that session.
How React.lazy() Changes Bundle Size
When you wrap a component in React.lazy(), that component and its imports are extracted into a separate chunk. This chunk only downloads when the component is actually needed.
The math: If your admin dashboard is 300KB and wrapped in React.lazy(), your initial bundle drops by ~300KB. Users who never visit that route never pay that cost.
Measuring the Impact
Check your build output:
build/
main.abc123.js 500KB → 200KB (after splitting)
chunk-admin.def456.js 300KB (lazy-loaded)
The initial load improved by 300KB. Your app bootstraps faster, especially on slow networks.
When Splitting Provides Value
Code splitting pays off when:
- The component is large (50KB+ with dependencies)
- It's rarely visited (admin panels, settings)
- It imports heavy libraries (charts, editors, date pickers)
Not worth it for:
- Small components (< 10KB)
- Components shown immediately on load
- Shared dependencies (they won't reduce bundle size)
The Real-World Metric
Focus on Time to Interactive (TTI)—how fast users can use your app. Cutting 200KB from the initial bundle can improve TTI by 1-2 seconds on 3G networks.
Key Takeaway: Code splitting with React.lazy() reduces initial bundle size by deferring large, infrequently-used components—measure bundle sizes before/after to confirm real savings.