Lesson 4.1

Code splitting and lazy boundaries

A dynamic import becomes a separate chunk that is fetched only when the code is first needed.

7mAdvanced5k students

Overview

Ship the code for this screen, not every screen

A dynamic import becomes a separate chunk that is fetched only when the code is first needed. Routes are the natural boundary; the second-best is anything behind a rare interaction, like an editor or a chart library inside a modal.

Every boundary needs a fallback, and the fallback should reserve the space the real component will occupy or you have traded a slow load for a layout shift.

Over-splitting has its own cost. Dozens of tiny chunks mean dozens of requests and a waterfall of dependent loads, which is often slower than one reasonably sized bundle.

In this lesson you will:

  • Split along routes and rare interactions
  • Give every lazy boundary a sensible fallback
  • Avoid splitting so finely that you add round trips

Resources

Previous Lesson
Next Lesson
Code splitting and lazy boundaries — React Performance Engineering — Vertex