Near-Zero Navigation Latency for Multi-Page Sites
With the Speculation Rules API, multi-page static and server-rendered sites can match or beat SPA route transitions by instructing the browser to prefetch or prerender high-probability internal links before the user finishes clicking.
Conservative Document Rules
Use "eagerness": "moderate" (which triggers when a user hovers over a link for ~200ms) combined with explicit URL exclusions so logout endpoints or external links are never prefetched:
<script type="speculationrules">
{
"prefetch": [
{
"source": "document",
"where": {
"and": [
{ "href_matches": "/*" },
{ "not": { "href_matches": "/logout*" } },
{ "not": { "selector_matches": "[data-no-prefetch]" } }
]
},
"eagerness": "moderate"
}
]
}
</script>
Guardrails for Responsible Prefetching
- Respect Data Saver & Battery: Browsers automatically disable speculative prefetching when the user enables Save-Data mode or low-memory limits.
- Avoid Side Effects on GET Routes: Ensure prefetched URLs are strictly idempotent reads and defer heavy analytics beacons until
document.prerenderingtransitions tofalse.