Configure Chrome Strict Speculation Rules Prerender2
In this article
Google Chrome does not allow users to directly configure strict speculation rules for prerender2 through standard settings menus. These rules are enforced automatically by Chrome based on site behavior, security policies, and resource constraints, and are primarily managed by web developers via JSON-based speculation rules hosted on websites.
Background on Speculation in Chrome
- Speculation in web browsers refers to predictive actions taken to improve perceived performance, such as prefetching resources or prerendering entire pages.
- Chrome has evolved its speculation strategies over time, from early
<link rel="prerender">tags to the modern Speculation Rules API. - The Speculation Rules API, introduced in Chrome 115+, uses a JSON format to define conditions under which pages may be prerendered, prefetched, or preconnected.
- Prerender2 is the second-generation prerendering system, designed to be more efficient and secure than its predecessor by isolating prerendered content in a sandboxed browsing context.
How Prerender2 and Speculation Rules Work
Prerender2 operates under strict conditions to ensure user privacy, security, and resource conservation. When Chrome predicts a user might navigate to a specific page (e.g., the top search result), it may prerender that page in the background. The process involves:- Chrome evaluating speculation rules defined by the target website in a JSON file (e.g.,
/speculationrules.json). - Checking whether the user meets criteria such as engagement signals (e.g., hovering over a link with a delay).
- Validating that the target page is same-origin or meets cross-origin embedding rules.
- Executing the prerender in a hidden, resource-constrained frame that cannot access sensitive APIs like camera, microphone, or notifications.
- Aborting the prerender if navigation conditions change or if the page attempts unauthorized actions.
localStorage or send cookies unless explicitly allowed under first-party contexts.
How Websites Define Speculation Rules
Web developers control speculation behavior by hosting a JSON configuration file that Chrome fetches and interprets. This file specifies which URLs can be prerendered and under what conditions. Example speculation rules JSON:{
"prerender": [
{
"source": "list",
"urls": ["/about", "/contact"],
"eligibility": "prediction",
"trigger": "navigation"
}
]
}
Key components:
- source: Where the URLs come from (e.g.,
list,allowlisting). - urls: The specific paths eligible for prerendering.
- eligibility: Conditions under which prerendering is allowed (e.g.,
predictionfor user intent). - trigger: What event initiates the speculation (e.g.,
navigation,hover).
<head> via:
<link rel="speculationrules" href="/speculationrules.json">
Chrome checks this file before initiating any prerender, and if rules are missing or invalid, speculation does not occur.
Common Problems and Limitations
Despite its benefits, prerender2 has several known limitations and failure modes:- Resource constraints: Prerendering may be blocked if the device is low on memory or battery.
- Cross-origin restrictions: Pages from different origins can only be prerendered if they opt in via HTTP headers (
Supports-Loading-Mode: fenced-prerender). - Aborted prerenders: If a prerendered page attempts to access restricted APIs (e.g.,
geolocation), Chrome cancels the process. - Cache and state issues: Prerendered pages do not share session storage with the main page, which can lead to inconsistent states if not handled properly.
- No user control: Users cannot enable, disable, or customize speculation rules through Chrome settings.
Browser and Feature Comparisons
While Chrome leads in speculation rule implementation, other browsers handle predictive loading differently:- Microsoft Edge: Based on Chromium, it supports the same Speculation Rules API and prerender2 features.
- Mozilla Firefox: Uses
<link rel="prefetch">and<link rel="prerender">but does not implement the Speculation Rules API. - Apple Safari: Implements limited prefetching but does not support prerendering due to privacy and resource concerns.
prerender tag from 2011, deprecated in 2023), prerender2 prevents tracking and abuse by isolating the prerendered page until activation.
Safety and Privacy Considerations
Chrome’s strict speculation rules are designed with privacy and security as core principles:- Prerendered pages run in a fenced frame, preventing access to most user data.
- No cookies or site data are sent during prerendering unless the origin explicitly allows it via the
Supports-Loading-Modeheader. - Navigation to a prerendered page only activates full access after the user clicks, ensuring no background tracking.
- Chrome logs speculation events in
chrome://tracingandchrome://prerenderfor debugging, but these are not user-facing controls.
Frequently Asked Questions
Can I enable strict speculation rules in Chrome manually?
No, users cannot manually enable or configure strict speculation rules. These are controlled by website-defined JSON rules and Chrome’s internal heuristics. There is no browser setting or flag to modify this behavior.Why doesn’t Chrome prerender some pages even if they have rules?
Prerendering may be blocked due to low device resources, cross-origin restrictions, user privacy settings, or if the page attempts to use disallowed APIs during prerendering. Chrome prioritizes stability and security over performance in such cases.Is prerender2 the same as the old Chrome prerender feature?
No. The original prerender (deprecated in 2023) loaded pages with full access to resources and APIs. Prerender2 uses a sandboxed environment (fenced prerender) to prevent abuse and improve security, making it fundamentally different.Do speculation rules work on mobile Chrome?
Yes, but with more restrictions. Mobile Chrome may disable prerendering more frequently due to battery, memory, or network constraints. The same rules apply, but eligibility is stricter on mobile devices.How can I test if my site’s speculation rules work?
Use Chrome DevTools: navigate tochrome://prerender to see active prerenders. Also, enable the Prerender2 logging category in chrome://tracing to monitor speculation events and debug failures.
Can websites detect if they are being prerendered?
Yes. Pages can checkdocument.prerendering (a boolean) and listen for the prerenderingchange event to adjust behavior during prerendering, such as delaying analytics or video playback.