Document.prerendering is a read-only instance property that returns true while the document is prerendering in the background via Speculation Rules. Learn MDN’s analytics pattern, prerenderingchange, activationStart, and five examples with try-it labs.
01
Kind
Read-only property
02
Returns
boolean
03
Active?
=== true
04
API
Speculation Rules
05
Event
prerenderingchange
06
Status
Experimental
Fundamentals
Introduction
Modern browsers can load pages in the background before the user clicks a link, using the Speculation Rules API. That hidden load is called prerendering. Scripts on the prerendered page need to know whether they are running in that background phase—that is what document.prerendering provides.
MDN: the read-only property returns true if the document is currently in the process of prerendering, and false if it is not. false is also returned for documents that have finished prerendering and for documents that were not prerendered.
💡
Delay until the user actually views the page
During prerender, the user has not committed to the navigation yet. MDN recommends deferring analytics, notifications, and other side effects until activation via prerenderingchange or activationStart.
On a non-prerendered page, initAnalytics() runs immediately in the else branch.
Example 5 — MDN Combined Prerender Detection
Detect prerendering now, activation after script ran, or a normal load (MDN).
JavaScript
if (document.prerendering) {
document.addEventListener(
"prerenderingchange",
() => {
console.log("Prerender activated after this script ran");
},
{ once: true },
);
} else if (performance.getEntriesByType("navigation")[0]?.activationStart > 0) {
console.log("Prerender activated before this script ran");
} else {
console.log("This page load was not via prerendering");
}
Document.prerendering is marked Experimental and Limited availability on MDN (not Baseline). Primarily Chromium with Speculation Rules. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Experimental · Limited availability
Document.prerendering
Read-only boolean — true while Speculation Rules prerender is in progress.
LimitedCheck compat
Google ChromeSupported with Speculation Rules
Supported
Mozilla FirefoxNot supported at time of writing
Not supported
Apple SafariNot supported at time of writing
Not supported
Microsoft EdgeChromium Speculation Rules
Supported
OperaFollow Chromium behavior
Partial
Internet ExplorerNo Speculation Rules API
Not supported
Document.prerenderingLimited availability
Bottom line: Feature-detect with "prerendering" in document. Delay side effects until prerenderingchange or check activationStart for past prerender.
Wrap Up
Conclusion
Document.prerendering tells you whether a page is loading in the background via Speculation Rules right now. Use it with prerenderingchange and activationStart to defer analytics and other side effects until the user actually views the page.
Listen for prerenderingchange when prerendering is true
Check activationStart for past prerender (MDN)
Keep a normal-load fallback in the else branch
❌ Don’t
Count prerender as a completed page view in analytics
Autoplay media during prerender without user intent
Assume every browser supports Speculation Rules
Rely on prerendering alone for past prerender detection
Assign to document.prerendering expecting to start prerender
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.prerendering
Boolean prerender status for Speculation Rules pages.
5
Core concepts
⚡01
Returns
boolean
API
✓02
Now?
=== true
Check
🔄03
Event
prerenderingchange
MDN
📈04
Past?
activationStart
Timing
⚠️05
Status
Experimental
MDN
❓ Frequently Asked Questions
A boolean. MDN: true if the document is currently in the process of prerendering via the Speculation Rules API; false if it is not, including after prerender finishes or when the page was never prerendered.
MDN marks Document.prerendering as Experimental and Limited availability (not Baseline). It is not Deprecated or Non-standard.
When the page is not prerendering, when prerender has finished and the page was activated, or when the page was loaded normally without prerender (MDN).
MDN: combine document.prerendering, the prerenderingchange event, and performance.getEntriesByType('navigation')[0]?.activationStart > 0.
MDN suggests delaying user-visible side effects until activation. Use prerenderingchange or check activationStart before starting analytics, ads, or autoplay.
hidden tells you whether the page is visible. prerendering tells you the document is loading in the background via Speculation Rules before the user navigates to it.
Did you know?
After a prerendered page is activated, document.prerendering becomes false. To detect that the page was prerendered, MDN recommends checking performance.getEntriesByType("navigation")[0]?.activationStart > 0 in addition to the property and prerenderingchange event.