JavaScript Document prerendering Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Limited availability
Experimental
Instance property

What You’ll Learn

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

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.

Related Document tutorials: hidden, activeViewTransition, Document constructor.

Understanding Document.prerendering

A read-only instance property on Document. Its value tells you whether prerender is in progress right now.

  • Valuetrue during prerender, false otherwise (MDN).
  • Read-only — reflects browser state; you cannot set it from script.
  • After activation — becomes false even if the page was prerendered (MDN).
  • Past prerender — use activationStart on navigation timing (MDN).
  • Status — Experimental and Limited availability (MDN).

📝 Syntax

JavaScript
document.prerendering

Value

A boolean — true while prerender is active, false when it is not (MDN).

MDN example — analytics during prerender

JavaScript
if (document.prerendering) {
  analytics.sendInfo("got this far during prerendering!");
}

MDN example — delay init until activation

JavaScript
if (document.prerendering) {
  document.addEventListener("prerenderingchange", initAnalytics, {
    once: true,
  });
} else {
  initAnalytics();
}

⚡ Quick Reference

GoalCode / note
Prerendering now?document.prerendering === true
Feature-detect"prerendering" in document
Wait for activationprerenderingchange event (MDN)
Was prerendered?navigation[0]?.activationStart > 0
Delay side effectsRun after activation, not during prerender
MDN statusExperimental & Limited availability

🔍 At a Glance

Four facts about document.prerendering.

Type
boolean

Read-only

True when
prerendering

Background load

False when
normal / done

Activated or never

Status
experimental

Not Baseline

📋 prerendering vs hidden

document.prerenderingdocument.hidden
FocusSpeculation Rules prerender phasePage Visibility API
True meansLoading in background before navigationTab is hidden from user
Typical useDelay analytics until activationPause video / timers when hidden
MDN statusExperimentalBaseline widely available

Examples Gallery

Examples follow MDN Document: prerendering. On a normal page load, document.prerendering is false—that is expected in try-it labs.

📚 Getting Started

Read the property on a normal page load.

Example 1 — Read on a Normal Page Load

When you open a page directly, prerendering is false.

JavaScript
console.log(document.prerendering);
// false on a normal navigation
Try It Yourself

How It Works

false means the document is not currently in an active prerender phase.

Example 2 — Feature Detect prerendering

Guard before reading the property in older browsers.

JavaScript
const supported = "prerendering" in document;
console.log("prerendering supported?", supported);

if (supported) {
  console.log("Currently prerendering?", document.prerendering);
}
Try It Yourself

How It Works

Chromium builds with Speculation Rules may expose the property even when the value is false.

📈 MDN Patterns & Activation

Defer work until the user actually views the page.

Example 3 — MDN Analytics During Prerender

Optionally log or measure behavior while prerender is active (MDN example).

JavaScript
if (document.prerendering) {
  analytics.sendInfo("got this far during prerendering!");
}
Try It Yourself

How It Works

Use this pattern only for diagnostics; prefer delaying user-facing side effects until activation.

Example 4 — Delay initAnalytics Until Activation

MDN pattern: wait for prerenderingchange when prerendering is true.

JavaScript
function initAnalytics() {
  console.log("Analytics initialized");
}

if (document.prerendering) {
  document.addEventListener("prerenderingchange", initAnalytics, {
    once: true,
  });
} else {
  initAnalytics();
}
Try It Yourself

How It Works

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");
}
Try It Yourself

How It Works

Combine all three signals to measure prerender activation rates accurately (MDN).

🚀 Common Use Cases

  • Delay analytics — avoid counting prerender as a full page view (MDN).
  • Defer ads / autoplay — start only after prerenderingchange.
  • Custom boot logic — skip heavy init while prerendering === true.
  • Activation metrics — measure how often prerenders become real visits.
  • Debugging Speculation Rules — verify scripts run during background load.
  • Safe defaults — fall back to normal init when the API is missing.

🧠 How Prerender Status Works

1

Browser starts prerender

Speculation Rules tell the browser to load a URL in the background.

Speculate
2

prerendering is true

Scripts on the hidden page can read document.prerendering === true.

Background
3

User navigates / activates

prerenderingchange fires; activationStart is set on navigation timing.

Activate
4

Property becomes false

Run deferred analytics and UI init now that the user is viewing the page.

📝 Notes

  • MDN: Experimental and Limited availability — Experimental banner shown above.
  • false does not mean “never prerendered”—check activationStart for past prerender (MDN).
  • Read-only boolean; you cannot force prerender from this property.
  • Pair with Speculation Rules markup on linking pages to enable prerender.
  • Related: hidden, activeViewTransition, Document constructor.

Browser Support

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.

Limited Check compat
Google Chrome Supported with Speculation Rules
Supported
Mozilla Firefox Not supported at time of writing
Not supported
Apple Safari Not supported at time of writing
Not supported
Microsoft Edge Chromium Speculation Rules
Supported
Opera Follow Chromium behavior
Partial
Internet Explorer No Speculation Rules API
Not supported
Document.prerendering Limited availability

Bottom line: Feature-detect with "prerendering" in document. Delay side effects until prerenderingchange or check activationStart for past prerender.

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.

Continue with readyState, hidden, pointerLockElement, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect with "prerendering" in document
  • Delay analytics until activation (MDN)
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about document.prerendering

Boolean prerender status for Speculation Rules pages.

5
Core concepts
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.

Next: readyState

Learn the document loading states loading, interactive, and complete.

readyState →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful