Preloading Routes on Link Hover
You'll learn how to start loading route code before navigation, making transitions feel instant.
The Concept
When you hover over or focus on a navigation link, there's a good chance you're about to click it. Why wait until the click to start loading that route's code? By preloading on hover, the JavaScript bundle downloads during the hover time (often 100-500ms), so when the user clicks, the component is already loaded and renders instantly.
This transforms the perceived performance: instead of "click → spinner → content," users experience "click → instant content."
How It Works
You've already learned to lazy load routes with React.lazy(). Now add a preload trigger. Import the lazy component's underlying promise and call it on mouse enter or focus:
const LazyAbout = React.lazy(() => import('./About'));
// Store the import promise so we can trigger it early
const preloadAbout = () => import('./About');
function Nav() {
return (
<nav>
<Link
to="/about"
onMouseEnter={preloadAbout}
onFocus={preloadAbout}
>
About
</Link>
</nav>
);
}
When the user hovers the link, preloadAbout() fires the dynamic import. Webpack caches it, so when the actual navigation happens and React.lazy() runs the same import, it's already resolved—no delay.
The Impact
This tiny addition can eliminate perceived loading time for 90% of navigations. Users hover before they click, giving you free preload time.
Key Takeaway: Preload route components on link hover/focus by triggering the dynamic import early—users get instant navigation without loading spinners for likely destinations.