Course contentsShow
← Web Development
Lesson 1423 of 2,98225. Build Tools and BundlersFree lesson

Code Splitting Trade-offs

Understanding when aggressive splitting hurts performance due to too many network requests.

Code Splitting Trade-offs

You'll learn: Why splitting your code too aggressively can actually slow down your application instead of speeding it up.

Code splitting isn't a "more is better" situation. While breaking your JavaScript into smaller chunks sounds great for performance, there's a critical balance to strike.

The Network Request Problem

Every code split creates a separate file that requires its own HTTP request. Even with HTTP/2 multiplexing, each request has overhead: DNS lookup time, connection negotiation, and round-trip latency. Split your code into 100 tiny chunks, and you've just forced the browser to juggle 100 separate network requests.

The analogy: Imagine grocery shopping. You could make one trip and carry everything at once (one large bundle), or you could make 50 trips carrying one item each time (aggressive splitting). Neither extreme is efficient—the sweet spot is a few well-planned trips.

When Splitting Hurts

  • Too granular: Splitting every small component into its own chunk means the overhead of fetching multiple files outweighs the benefit of parallel loading
  • Too many entry points: Each route or feature split multiplies your HTTP requests
  • Small chunks: A 2 KB chunk still requires a full network round trip—the request cost exceeds the payload benefit
  • Waterfall loading: If split chunks depend on each other, they load sequentially, not in parallel, creating cascading delays

Finding the Balance

Aim for chunk sizes between 20-200 KB where the network overhead is justified by meaningful lazy-loading opportunities. Focus on route-level and major feature splits rather than component-level splits. Use your bundle analyzer to identify genuinely large dependencies worth isolating, not every small utility.

Key Takeaway: Code splitting is about strategic separation, not maximum fragmentation—fewer, purposeful splits often outperform many tiny ones due to reduced network overhead.