Performance glossaryPrefetching is downloading resources, or whole pages, a visitor is likely to need next before they ask for them, so the next step loads faster.
Prefetching means fetching something before it is needed, on a good guess that it soon will be. Most often that is the next page a visitor is likely to open, or a file that page needs. When the visitor clicks, the response is already in the browser's cache, and the page appears almost immediately. The cost is the bandwidth spent on guesses that turn out wrong.
In most cases a site has to tell the browser what to prefetch, either with resource hints in the HTML or with the Speculation Rules API.
Prefetching and related hints
| Hint | What it does | Use it for |
|---|---|---|
dns-prefetch | Looks up a domain's IP address early | Third-party domains the page will use |
preconnect | Opens the connection early: DNS, TCP, and TLS | One or two critical third-party origins, such as a font or image CDN |
prefetch | Downloads a resource at low priority into the cache | Files or pages likely to be needed on the next navigation |
preload | Downloads a resource for the current page at high priority | Critical files the browser would find late, such as the hero image or a key font |
| Speculation rules | Prefetches, or fully prerenders, whole pages according to rules | Likely next pages on the same site |
A simple prefetch hint looks like <link rel="prefetch" href="https://example.com/pricing/">. Strictly, preload is not prefetching, because it is for the current page, but the two are often confused; see preloading key requests. Preloading something that is not needed straight away competes with the files that are.
Speculation rules
The Speculation Rules API, supported in Chromium-based browsers such as Chrome and Edge, lets a site describe which links to prefetch or prerender and how eagerly: as soon as the page loads, when a visitor hovers over a link, or when they start to click it. Prerendering goes further than prefetching, loading and rendering the whole page in the background so it can appear instantly.
WordPress core now outputs speculation rules that prefetch a page when a logged-out visitor starts clicking a link. Developers can adjust or disable this with filters, and the WordPress Performance Team's Speculative Loading plugin offers more aggressive settings, including prerendering. Other frameworks have their own options, such as Astro prefetch.
Benefits and costs
- Faster next pages. A prefetched page skips the wait for the server, so navigation feels instant or close to it.
- Wasted data when the guess is wrong, which matters to visitors on mobile plans.
- Extra server load, since prefetched pages are requested whether or not anyone views them. Cached pages make this cheap; uncached dynamic pages make it expensive.
- Analytics: prerendered pages run their scripts, so analytics should count a page view only when the page is actually shown.
Common mistakes
- Prefetching links that change something when visited, such as logout, add-to-cart, or delete URLs. These must always be excluded.
- Prefetching every link on the page eagerly, which wastes bandwidth and server capacity.
- Adding
preconnectfor many origins. Each open connection costs resources, so keep it to the few that matter.
Source: MDN: rel=prefetch.