In JavaScript, the Document prerenderingchange event fires on a prerendered document when it is activated — the user actually views the page (MDN). A generic Event.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for prerenderingchange. Start with this line.
JavaScript
addEventListener("prerenderingchange", fn)
Call
What it does
addEventListener("prerenderingchange", fn)
Primary signature.
Built into the browser. Listen with document.addEventListener("prerenderingchange", …) — no import required.
Library declarations
JavaScript
addEventListener("prerenderingchange", fn)
Parameters
Parameter
Description
prerenderingchange
Optional. Runs after the user activates the page
Return Value
Return Value
Description
*
Fires as a Document event (listener receives the Event object).
JavaScript Examples
Example 1 — Defer Analytics Until Activation
MDN pattern: wait for prerenderingchange only while prerendering.
JavaScript
function initAnalytics() {
console.log("Analytics initialized");
}
if (document.prerendering) {
document.addEventListener("prerenderingchange", initAnalytics, {
once: true,
});
console.log("Waiting for prerenderingchange...");
} else {
initAnalytics();
}
Feature-detect. Guard with "prerendering" in document.
Wait if needed. Only attach the event while currently prerendering.
Else call now. Unsupported browsers and normal loads run fn immediately.
Reuse. Pass any side-effect callback — analytics, ads, autoplay setup.
Compatibility
Browser Support
Documentprerenderingchange is part of Prerendering Revamped / Speculation Rules. MDN marks it Experimental and Limited availability (not Baseline). It is not Deprecated or Non-standard — still feature-detect in production.
✓ Experimental · Limited availability
Document prerenderingchange
Fires when a prerendered document is activated (user views the page). Pair with document.prerendering.
LimitedFeature-detect required
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
prerenderingchangeLimited
Bottom line: Support tracks Speculation Rules prerender. Always feature-detect, use the defer pattern for side effects, and add activationStart when measuring.
Frequently Asked Questions
It fires on a prerendered document when it is activated — that is, when the user actually views the page after Speculation Rules prerender (MDN).
MDN marks Document prerenderingchange as Experimental and Limited availability (not Baseline). It is not Deprecated or Non-standard.
When document.prerendering is true, add a once listener for prerenderingchange to run code after activation. If prerendering is false, run that code immediately (MDN).
Not safely by itself. MDN notes the defer-init pattern can miss activations that already happened. Combine prerendering, prerenderingchange, and navigation activationStart.
A generic Event. Listen with document.addEventListener("prerenderingchange", …) or document.onprerenderingchange.
Analytics, ads, autoplay, client storage writes, and other side effects that assume the user is viewing the page. See MDN’s Speculation Rules unsafe speculative loading guidance.