Sub-Zero Latency with the Speculation Rules API: Chrome Prerender and Prefetch Architectures
How to achieve instant, 0ms TTFB and near-zero LCP navigations using declarative speculation rules without corrupting analytics telemetry.
The Speculation Rules API is the modern web platform standard for proactive page prefetching and full background prerendering. Replacing legacy `<link rel="prerender">` tags, speculation rules give developers granular control over eagerness levels (`immediate`, `moderate`, `conservative`), URL patterns, and device resource constraints. When implemented correctly, clicking a link displays the target page instantaneously, driving LCP to near zero.
THE PRODUCTION PROBLEM STATEMENT
Traditional client-side link prefetch scripts trigger aggressive network requests on hover, burning user mobile data and corrupting server analytics by counting page views for pages the user never opened.
Declarative Prerendering with Speculation Rules
Speculation rules are declared in JSON format inside a `<script type="speculationrules">` element in the document `<head>`.
Rules define either `prefetch` (downloading HTML only) or `prerender` (rendering the full page in an invisible background tab). The `eagerness` setting allows you to specify whether the speculation triggers immediately, on link hover (`moderate`), or on mouse down / touch start (`conservative`).
<script type="speculationrules">
{
"prerender": [
{
"source": "document",
"where": {
"and": [
{ "href_matches": "/articles/*" },
{ "not": { "href_matches": "/articles/draft/*" } }
]
},
"eagerness": "moderate"
}
]
}
</script>Preserving Analytics Accuracy: Handling Page Activation
Because prerendered pages execute JavaScript in a hidden background tab, logging page views immediately upon script execution will artificially inflate traffic numbers for pages the user never opened.
Always check `document.prerendering`. If true, listen for the `prerenderingchange` event before firing analytics page view beacons.
function trackPageView() {
analytics.send({ path: window.location.pathname });
}
if (document.prerendering) {
// Page is loaded in background; wait for user to click and activate it!
document.addEventListener('prerenderingchange', () => {
trackPageView();
}, { once: true });
} else {
// Standard direct page load
trackPageView();
}[PROBABLE CAUSE] The target page uses an unsupported feature (like window.open or WebSockets) before activation, or has conflicting headers.
[VERIFIED RESOLUTION] Inspect the DevTools Application -> Speculative Loads panel to see the exact cancellation reason.
Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
The browser automatically respects user preferences and OS constraints, disabling prerender rules when Data Saver or battery saver modes are active.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Mastering Core Web Vitals: Engineering for Sub-100ms INP and Optimal LCP
A technical blueprint for diagnosing Interaction to Next Paint bottlenecks, accelerating Largest Contentful Paint, and maintaining zero Cumulative Layout Shift in production.
Architectural Blueprint for Modern Business Websites: Speed, SEO, and Conversion Engineering
How to structure multi-page web platforms that achieve perfect Lighthouse scores, rank on search engines, and convert visitors into qualified business inquiries.