0
Challenge · 35Hooks & Effects
Lazy Loading
Performanceused in ~65% of apps
By default every component you import is stitched into one JavaScript bundle the user must download before the page can run — including the chart, the rich-text editor, and the settings modal almost nobody opens. Lazy loading lets you ship that code as a separate file that downloads only when it's actually rendered, so the first load stays small and fast.
Core idea. React.lazy(() => import('./Heavy')) defers loading a component's code until it first renders. The dynamic import() splits that component into its own chunk; React downloads the chunk on demand and, while it's in flight, shows the nearest <Suspense fallback>.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
How is the heavy widget bundled?
what the browser downloads first48 kB
core 48kB
chunk loads on demand
initial page load~0.4s
<Dashboard />heavy widget: code not loaded
Initial download is just the core (48 kB) — fast first paint. The 190 kB widget loads only when opened.
↑ play a little first, then dig in