Course contentsShow
← Web Development
Lesson 1964 of 2,98236. Performance Optimization TechniquesFree lesson

Prefetch for Future Navigation

Download resources that will likely be needed for future navigations using prefetch during idle time.

What You'll Learn

You'll learn how to use the prefetch resource hint to download resources during idle time that will likely be needed when the user navigates to the next page.

What is Prefetch?

Prefetch tells the browser to download low-priority resources in the background that you anticipate the user will need soon—but not on the current page. Think of it like packing snacks for later in your trip: you're not eating them now, but you know you'll want them when you reach your next destination.

Unlike preconnect (which opens connections) or DNS prefetch (which resolves domain names), prefetch actually downloads complete resources like JavaScript files, CSS, images, or even entire HTML documents.

How Prefetch Works

The browser downloads prefetched resources during idle time using spare bandwidth, storing them in the cache. When the user actually navigates to that page, the browser checks its cache first—instant delivery!

<!-- Prefetch the next page's JavaScript bundle -->
<link rel="prefetch" href="/page2.bundle.js">

<!-- Prefetch the next likely page itself -->
<link rel="prefetch" href="/checkout.html">

<!-- Prefetch images users will see on the next page -->
<link rel="prefetch" href="/product-gallery-large.jpg">

When to Use Prefetch

Use prefetch when you have high confidence about where users will navigate next:

  • The next step in a multi-page form
  • Checkout pages from product pages
  • Article pages from a blog homepage
  • Common user journeys identified through analytics

Caution: Only prefetch what's truly likely. Wasting bandwidth on resources users never request hurts performance and costs mobile users money.

Prefetch vs Preload

Remember: preload is for resources needed on the current page, while prefetch is for future pages.

Key Takeaway: Use <link rel="prefetch"> to download resources during idle time that users will likely need on their next navigation, making future page loads feel instant.