Avoiding Over-Splitting
What you'll learn: How splitting your app into too many small chunks can hurt performance instead of helping it.
You've learned that code splitting reduces bundle size and speeds up initial load. But there's a trap: splitting too aggressively can make things worse, not better.
The Over-Splitting Problem
Every code split creates a separate chunk that requires its own HTTP request. When you have dozens of tiny chunks (say, 5-10 KB each), you introduce request overhead:
- Each request has latency (even on HTTP/2)
- Browsers must parse and evaluate each chunk separately
- You create waterfalls where one chunk loads, reveals it needs another chunk, which loads and reveals yet another dependency
Analogy: Imagine ordering groceries. One delivery with 20 items is efficient. But if you order each item separately—20 deliveries—the overhead of 20 trips drowns out any benefit.
Finding the Right Granularity
From your measurement lessons, you know to profile. For splitting, ask:
- Is this chunk used on multiple routes? If yes, shared chunks reduce duplication.
- Is it larger than ~20-30 KB minified? Smaller splits often aren't worth the request.
- Does it create a waterfall? If Component A lazy-loads B which lazy-loads C, users wait through multiple round-trips.
Route-based splitting typically hits the sweet spot: each route is substantial enough to justify the request, and users navigate intentionally. Component-level splits should be rare and reserved for truly heavy, conditionally-rendered components (like a chart library).
What Good Splitting Looks Like
- 5-10 meaningful chunks, not 50 tiny ones
- Each chunk represents a significant feature or route
- Critical path components load together, not in sequence
Key Takeaway: Code splitting is about strategic cuts, not relentless slicing—measure bundle sizes and request waterfalls to find the balance between too few and too many chunks.