Speculation rules in WordPress: the next page before the click

WordPress 6.8 prefetches a page when the visitor presses a link. WP Core Web Vitals turns that into Adaptive Speculation: with the page cache on, links are prefetched early and the page a visitor is about to open is prerendered, so it's on screen the moment they click.

WP Core Web Vitals page loading settings: Adaptive Speculation and YouTube and Vimeo facades

Does WordPress already use speculation rules?

Yes, since 6.8. WordPress adds a speculation rule to every page for logged-out visitors: prefetch, with conservative eagerness, so the next page's HTML is fetched when the visitor presses the link. That saves a little. Prefetching earlier saves more, and prerendering saves the whole page load, but both cost your server a request for every link they speculate on. WP Core Web Vitals changes WordPress' rule depending on whether the page cache is on.

How Adaptive Speculation works

  • With the page cache on, a prefetch costs your server next to nothing, so links are prefetched early (eager: on desktop when the pointer touches a link, on mobile when the link scrolls into view). On top of that, a prerender rule renders the page in the background when the visitor shows intent (moderate: on desktop after a 200 ms hover or on press, on mobile when scrolling stops near a link).
  • With the page cache off, every prefetch would hit PHP, so the plugin only prefetches, with moderate eagerness.

The plugin configures the rule WordPress prints, so WordPress' exclusions keep working (the admin, the login page, files, nofollow links, URLs with parameters) and so do those of other plugins. Its prerender rule uses the same conditions. Links with the class no-prefetch or no-prerender are skipped.

WooCommerce's cart, checkout and account pages are never speculated. A prerendered checkout could start a session or count a visit nobody made.

Speculation rules work in Chrome and Edge. Other browsers ignore them and load the page on click.

Check your analytics before you prerender

A prerendered page runs its JavaScript, including analytics. Google Analytics 4 waits until the page is shown before it counts it. Not every tool does: a script that doesn't wait counts a page view for every page that is prerendered and never opened. If your page views jump with Adaptive Speculation on, that's the cause; choose Custom with prefetch, or fix the script.

The page loading settings

WP Core Web Vitals page loading settings: Adaptive Speculation and YouTube and Vimeo facades

Speculative loading

Mode: Adaptive as above (the default). WordPress leaves its own rule as it is. Custom lets you pick the Action (prefetch or prerender) and the Eagerness: conservative (on press), moderate (on hover on desktop) or eager (earlier still; use it only with the page cache on). Off switches speculative loading off. Adaptive

Never speculate

One path per line, * as wildcard, for pages that must not load before the click: a logout link, a page that counts something. Empty

YouTube and Vimeo facades

An embedded video becomes its thumbnail with a play button. The player, hundreds of kilobytes of JavaScript, loads when the visitor clicks and then starts playing. On

Fine-tuning

Page loading fine-tuning: lazy load iframes, minify HTML and render the footer later
  • Lazy load iframes (On): other iframes, such as maps and forms, load when they come near the viewport.
  • Lazy load iframes with JavaScript (Off): for browsers without native lazy loading. Rarely needed.
  • Minify HTML (On): removes whitespace and comments. Turn it off if invalid HTML breaks your layout.
  • Render the footer later (Off): adds content-visibility: auto to the footer, so the browser skips rendering it until it's near the viewport. Fill in Footer selector when your footer isn't a footer element.

When to turn speculation down

Use WordPress' default (prefetch on press) or Off when your host charges per request or when most links lead to pages the cache skips. Speculation does nothing for the first page a visitor opens: that one still needs a fast server and an early LCP image.

Speculative loading

Questions about speculation rules in WordPress

Does prerendering put extra load on my server?

A little. Adaptive Speculation only prerenders with the page cache on, so the page comes from the cache and isn't built again, and Chrome keeps at most two prerenders at a time.

Do I need a separate speculation rules plugin?

No. WordPress 6.8 has speculative loading built in, and WP Core Web Vitals configures it. A second plugin that also changes the speculation rules would fight over the same setting.

Why don't I see speculation rules when I'm logged in?

WordPress only adds them for logged-out visitors, and only with pretty permalinks. Check in a private window: DevTools, Application, Background services, Speculative loads shows what was prefetched or prerendered.

The background: instant loading pages with speculation rules, prerender until script and the speculation rules generator.