Code splitting saves bandwidth on initial load, but naive splitting introduces navigation latency: when a user clicks a route or modal button, they must pause while the browser makes a round-trip network request to fetch the JavaScript chunk. Prefetching strategies bridge this gap by intelligently downloading code chunks ahead of user interaction.
Consider this user timeline without prefetching:
analytics.chunk.js (305ms).With Hover/Intent Prefetching, the chunk starts downloading at 0ms. By 300ms, the chunk is already cached in browser memory, rendering the view immediately on click.
Because dynamic import() returns a standard JavaScript Promise, you can trigger chunk evaluation on standard DOM events:
Modern bundlers support declarative prefetching annotations embedded inside dynamic import() statements:
webpackPrefetch: true: Injects <link rel="prefetch" href="admin-report.chunk.js"> into the document <head>, downloading the chunk during browser idle time after the parent page finishes loading.webpackPreload: true: Injects <link rel="preload">, instructing the browser to download the chunk with high priority alongside the parent page.For bottom-of-page sections or long infinite feeds, prefetch chunks when a scroll anchor enters the viewport using IntersectionObserver:
Never waste cellular mobile data. Use navigator.connection to disable aggressive prefetching on slow connections or when Data Saver mode is enabled:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Component-Level Lazy Loading with Suspense | Analyzing Bundle Sizes with Rollup and Webpack Visualizer |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.