On the web, prefetching is fetching ahead: while a visitor reads the current page, the browser quietly downloads the page they're most likely to open next. When they click, the browser already has it and shows it much faster.
You can ask for it in two ways: the older <link rel="prefetch"> tag, and the newer Speculation Rules API, which is built for prefetching whole pages.
(Prefetch has other meanings in computing. Windows keeps a Prefetch folder that helps programs start faster, and processors prefetch data into their caches. This article is about prefetching in web pages.)
Prefetch compared with the other hints
Browsers offer several hints for loading things early. They differ in what they fetch and for which page:
| Hint | What it does | For which page |
|---|---|---|
dns-prefetch |
Looks up a domain's IP address | This page |
preconnect |
Opens a connection to a server | This page |
preload |
Downloads a file the page needs now, at high priority | This page |
prefetch |
Downloads a file or page, at low priority | A later page |
prerender (via speculation rules) |
Loads and runs a whole page in the background | A later page |
The key point: prefetch is about the next page, so the browser treats it as the least urgent thing on the current one.
Link prefetch: one tag per file
<link rel="prefetch" href="/pricing/">
The browser downloads /pricing/ when it has spare capacity and keeps the result in its HTTP cache. If the visitor then opens that page, it comes from the cache. You can prefetch a page or a file the next page needs, such as a large script.
Know its limits before you rely on it:
- Same site only, in practice. Browsers now keep separate caches per site, so a prefetch of another site's page can't be used when the visitor goes there.
- Caching headers apply. A
Cache-Control: no-storeorno-cacheheader on the target can stop it. - Not every browser. Chrome, Edge and Firefox support it; Safari supports it only behind a hidden setting.
- In the HTML, not a header. The HTML standard gives the prefetch hint no effect when it's sent as an HTTP
Linkheader.
For prefetching whole pages, MDN recommends the Speculation Rules API instead, where it's supported.
Speculation rules: prefetch pages by pattern
The Speculation Rules API lets you describe which links to prefetch, and when, in a small block of JSON:
<script type="speculationrules">
{
"prefetch": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
This rule prefetches any link to a page on your own site when the visitor shows interest in it. The eagerness setting decides what counts as interest:
| Eagerness | When it fires in Chrome |
|---|---|
immediate |
As soon as the rules are seen |
eager |
Soon after a link gets attention: a very short hover on desktop, a link entering the screen on mobile |
moderate |
Holding the pointer over a link for 200 ms on desktop; on mobile, links near your last touch shortly after you stop scrolling |
conservative |
Pressing on the link (pointer or touch down) |
A speculation-rules prefetch downloads the page's HTML, not its images or scripts, and keeps it in memory for the current page only. Leave the page, and unused prefetches are thrown away. Chrome also caps how much it does: up to 50 immediate prefetches, and two at a time for the other settings, where a new one replaces the oldest.
Browsers skip these prefetches when the visitor's device is in Data Saver or Battery Saver mode. Prefetches to other sites only work if the visitor has no cookies for that site, for privacy. MDN still marks the API experimental, with limited browser support, so treat it as a bonus for the browsers that have it, not a requirement.
What not to prefetch
A prefetch is a real GET request to your server. It arrives with a Sec-Purpose: prefetch header, so your server can tell it apart, but it still runs whatever that URL does. Keep these out of your rules:
- sign-out and language-switch links,
- "add to cart" links,
- links that send a one-time code or count against a quota.
Prefetching costs too. Visitors download pages they may never open, and your server answers requests that never turn into visits. Start with pages people very likely open next, such as the next step of a checkout or the second page of a list, and widen from there.
Does prefetching help SEO?
Not directly. It doesn't change how Google crawls, indexes or ranks your pages. What it changes is how fast the next page appears for your visitors, which is the page speed they actually feel. If you want a page to load instantly, including running its scripts, look at prerendering, which uses the same speculation rules but costs much more memory and bandwidth.