PerformanceSpeculation RulesCore Web VitalsTechnical SEOJavaScript

Speculation Rules API: instant navigations with prefetch and prerender

Pablo Alcalde García

One of the most effective ways to make a website “feel” instant is not optimising the current page, but having the next one already ready. The Speculation Rules API lets you tell the browser which pages the user is likely to visit so it can prefetch them or even prerender them ahead of time. When the user clicks, the navigation is almost immediate.

Prefetch and prerender: the difference

PrefetchPrerender
What it doesDownloads the document (HTML)Loads and renders the full page in the background
BenefitSaves the network waitPractically instant navigation
CostLowHigher (CPU, memory, network)
RiskMinimalSide effects if the page runs code on load

How it is declared

It is done with a <script type="speculationrules"> block containing JSON:

<script type="speculationrules">
{
  "prerender": [
    {
      "where": { "href_matches": "/blog/*" },
      "eagerness": "moderate"
    }
  ],
  "prefetch": [
    {
      "where": { "and": [
        { "href_matches": "/*" },
        { "not": { "selector_matches": "[rel~=nofollow]" } }
      ]},
      "eagerness": "conservative"
    }
  ]
}
</script>

What eagerness is

It controls when speculation happens:

  • immediate: as soon as the rule is evaluated (very aggressive).
  • eager: early, on slight hints.
  • moderate: when hovering over the link for a moment (or equivalents).
  • conservative: only when starting to press (mousedown / touchstart).

Start with moderate or conservative: they balance speed and waste.

Compatibility: progressive enhancement

This API is implemented in Chromium-based browsers and not in all others. Browsers that don’t understand it simply ignore the block, so it is a progressive enhancement with no risk of breaking anything. Check current support on caniuse before relying on it.

The risks you must control

Prerender runs the page before the user sees it. That can cause problems if your page:

  1. Counts visits or fires analytics on load: pages nobody actually saw would be recorded.
  2. Runs actions with side effects (sending something, marking as read, redeeming a coupon) on load.
  3. Depends on session state in a sensitive way.

Two defences:

// Run analytics only when the page is actually activated
if (document.prerendering) {
  document.addEventListener('prerenderingchange', startAnalytics, { once: true });
} else {
  startAnalytics();
}

And exclude routes with side effects from speculation (logout, actions, cart):

{ "not": { "href_matches": "/logout" } }

Which pages to speculate on

  • The most likely next page: from the list to the detail, from the home page to the flagship product.
  • Main menu links.
  • Light pages with no side effects on load.

Avoid speculating on everything: you waste the user’s bandwidth and your server’s resources for nothing.

In frameworks and static sites

  • Astro includes a built-in link prefetch option; you can complement it with speculation rules in the layout’s <head>.
  • Nuxt automatically prefetches routes with <NuxtLink>; speculation rules can be added via useHead.
  • On a static site, it is enough to add the <script> to the common layout.

This complements the initial-load optimisation I explain in Core Web Vitals and the interaction performance of reducing INP.

How to check it works

In Chrome DevTools → Application → Speculative loads you can see which rules were detected and which pages were preloaded or prerendered, and the reason if not.

Does it improve SEO?

Indirectly: faster navigations improve the experience and usage metrics. It is not a ranking signal in itself, and it doesn’t change what crawlers see. As always, the foundation is solid technical work (technical SEO).

Conclusion

Speculation Rules is a low-risk, high-perceived-impact progressive enhancement, as long as you control prerender side effects. Start with prefetch and eagerness: moderate on your main routes, measure and expand.

If you want your site to feel instant and pass Core Web Vitals, let’s talk.

Call me now