Preloading on Hover for Instant Feel
You'll learn how to make lazy-loaded components feel instant by starting their download when users hover over trigger elements, hiding network latency before the click happens.
The Problem with Lazy Loading
When you use React.lazy() and only load components on demand, there's a noticeable delay: the user clicks a button, then the component starts downloading, then it renders. This creates a sluggish experience, especially on slower connections.
The Solution: Predictive Preloading
Instead of waiting for the click, start importing the lazy component when the user hovers over (or focuses on) the trigger element. By the time they click—typically 200-500ms later—the component is already loaded and ready to render instantly.
Think of it like a restaurant preparing your order as you walk toward the counter, rather than waiting until you've placed it. The technical action happens during the "intention signal" (hover), not the "action signal" (click).
How It Works
You store a reference to the lazy component's import promise. On hover/focus, you call that import function to trigger the download early. When the user actually clicks, React finds the component already cached and renders it immediately:
const LazyDashboard = React.lazy(() => import('./Dashboard'));
// Store the import function for preloading
const preloadDashboard = () => import('./Dashboard');
function Navigation() {
return (
<button
onClick={() => setShowDashboard(true)}
onMouseEnter={preloadDashboard}
onFocus={preloadDashboard}
>
Go to Dashboard
</button>
);
}
The onMouseEnter and onFocus handlers trigger the network request early. When the user clicks, the chunk is already downloaded and the Suspense boundary resolves almost instantly.
Key Takeaway: Preloading on hover transforms lazy loading from a performance compromise into an invisible optimization—users get instant interactions while still benefiting from smaller initial bundles.