Achieving sub-100-millisecond page navigations has long been the holy grail of web performance. While traditional link prefetching (<link rel="prefetch">) downloads subresources into the browser cache ahead of time, the browser must still parse HTML, execute scripts, and render the page layout upon click. The modern Speculation Rules API unlocks full background prerendering (Prerender2) in Google Chrome. By declaring JSON-based speculation rules, developers instruct Chrome to instantiate an invisible background renderer process that fetches, parses, compiles, and renders target web pages completely before the user even clicks the link.
Understanding Speculation Rules Actions: Prefetch vs Prerender
Speculation rules allow web authors to define speculation intent using two distinct actions:
prefetch: Fetches the document and response body into the HTTP cache without evaluating JavaScript or rendering layout.prerender: Boots an invisible renderer process, executes scripts, builds the DOM tree, and performs layout. When the user clicks the link, Chrome instantly swaps the prerendered page into view, achieving a 0ms perceived navigation time (Largest Contentful Paint).- Eagerness Controls: Rules support
immediate(prerenders on page load),eager(prerenders at the earliest opportunity),moderate(prerenders on hover or pointer-down), andconservative(prerenders on mousedown/touchstart).
Configuring Inline Speculation Rules in HTML
Deploy speculation rules using a <script type="speculationrules"> block:
<!-- Instant navigation configuration -->
<script type="speculationrules">
{
"prerender": [
{
"where": {
"and": [
{ "href_matches": "/articles/*" },
{ "not": { "href_matches": "/articles/logout" } },
{ "not": { "selector_matches": ".no-prerender" } }
]
},
"eagerness": "moderate"
}
]
}
</script>
Delivering Speculation Rules via HTTP Response Headers
For large multi-page enterprise sites, speculation rules can be delivered centrally via the Speculation-Rules HTTP header without altering HTML templates:
# Nginx server configuration
add_header Speculation-Rules "/rules/speculation.json" always;
# Apache HTTP Server (.htaccess / virtual host)
Header always set Speculation-Rules "/rules/speculation.json"
Auditing Prerendering in Chrome DevTools
To inspect and audit speculation rules live in Google Chrome:
- Open Google Chrome and navigate to your website.
- Open Chrome DevTools by pressing Ctrl + Shift + I (or Option + Command + I on macOS).
- Switch to the Application tab.
- Under the Background Services category in the left tree, select Speculative loads.
- Review the Rules tab: Chrome displays registered JSON speculation rules, syntax status, and target URLs.
- Hover over a matched link on the page. In the Speculations table, observe the status transition from Ready to Success.
- Click the link: observe that navigation occurs instantaneously with 0ms LCP.
Managing Prerendering Lifecycle Restrictions
Chrome restricts certain APIs inside prerendered background pages until activation to prevent intrusive user disruptions. APIs that trigger audio playback, invoke notifications, or access camera/microphone are deferred until the user activates the page.