Prefetching Split Chunks
What you'll learn: How to load code-split chunks before a user needs them, eliminating the loading delay when they navigate.
The Problem with Lazy Loading
Code splitting with React.lazy() is powerful, but there's a catch: when a user clicks a link to a lazily-loaded route, they must wait for the chunk to download before seeing content. That brief delay hurts perceived performance.
The Prefetch Strategy
Prefetching means loading chunks in advance during idle time. You're essentially saying: "I think the user might go here next—let's download it now while they're reading the current page."
Browser-Level Prefetching
You can use the <link rel="prefetch"> hint in your HTML:
<link rel="prefetch" href="/static/js/AdminPanel.chunk.js" />
The browser downloads this file at low priority during idle time. When the user actually navigates to that route, the file is already cached—instant render.
React Router Prefetching
If you use React Router, you can prefetch on link hover:
<Link
to="/admin"
onMouseEnter={() => import('./AdminPanel')}
>
Admin
</Link>
When the user hovers over the link (a strong navigation signal), you trigger the chunk download. By the time they click, it's ready.
When to Prefetch
- High-probability routes: Dashboard users often visit settings
- Next step in a flow: After checkout, prefetch the confirmation page
- Hover intent: User hovering = likely to click
Don't prefetch everything—you'll waste bandwidth and slow down critical resources.
Key Takeaway: Prefetching split chunks eliminates the wait time of lazy loading by downloading code during idle moments, making navigation feel instant while keeping initial bundles small.