Adaptive Speculation for WordPress

WP Core Web Vitals sets WordPress' speculation rules to match your page cache. With the cache on, the browser fetches links early and prerenders the page a visitor is about to open, 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 browser fetches the next page's HTML when the visitor presses the link. That saves a little. Prefetching earlier saves more and a prerender has the whole page ready, but both cost your server a request for every link they speculate on. WP Core Web Vitals sets that rule to what your server can take: bolder with the page cache on.

Built on your page cache

A page from the cache costs your server next to nothing, so with the page cache on, Adaptive Speculation prefetches links early and prerenders the page once the visitor shows intent, such as a hover on desktop. Without the page cache every prefetch builds a page in PHP, so Adaptive Speculation only prefetches, and only on intent.

The plugin works through WordPress' own speculative loading, so WordPress' exclusions and those of other plugins keep working. It never speculates on WooCommerce's cart, checkout and account pages.

Speculation rules work in Chromium browsers such as Chrome and Edge. Safari and Firefox ignore them and load the page on click.

The page loading settings

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

Speculative loading

The browser starts on the next page before the visitor clicks. A prefetched page skips the wait for your server after the click (TTFB), and a prerendered page is on screen at once. The plugin sets this through WordPress' own speculative loading. The modes:

  • Adaptive follows your page cache. With the cache on, the browser prefetches links early and prerenders a page as soon as the visitor shows intent, such as a hover on desktop. Without the cache it only prefetches, and only on that intent, because every prefetch would cost your server a page built in PHP.
  • WordPress keeps WordPress' own rule, which prefetches only when the link is pressed.
  • Custom lets you choose the action and the eagerness yourself.
  • Off removes speculative loading, WordPress' rule included.

A prerendered page runs its JavaScript. Google Analytics 4 waits until the page is shown before it counts it, so check that your other analytics do the same. Adaptive

Action

Shows with Custom. Prefetch downloads the next page's HTML, so after the click the visitor no longer waits for your server. Prerender also renders the page with its images and scripts, so it appears at once. That costs your server more for every page nobody opens, so choose Prerender only with the page cache on, as Adaptive does. Prefetch

Eagerness

Shows with Custom, and decides when the browser starts on the next page:

  • Conservative: when the visitor presses the link.
  • Moderate: when the visitor hovers over the link on desktop. On a phone Chrome picks links from what is in view.
  • Eager: at the first hint, such as a short hover on desktop or a link that comes into view on a phone.

The earlier it starts, the more time it saves. It also sends your server more requests for pages nobody opens, so keep Eager for a site with the page cache on. Moderate

Never speculate

Paths the browser must never load before the click, such as a page that counts its visits or a one-time link. Fill in one path per line, with * as wildcard, for example /members/*. WooCommerce's cart and checkout are always left out, and so are its account pages. In your theme, a link with the class no-prefetch is never loaded early, and one with no-prerender may still be prefetched but is never prerendered. Empty

YouTube and Vimeo facades

An embedded YouTube or Vimeo video shows its thumbnail with a play button, and the player, hundreds of kilobytes of JavaScript, loads when the visitor clicks and starts playing at once. Until that click the player doesn't compete with your LCP image or keep the main thread busy while visitors scroll and tap (INP). The facade has the player's size, so nothing moves when the video starts. A YouTube playlist keeps the normal player, because it has no single thumbnail. On

Fine-tuning

Page loading fine-tuning: lazy load iframes, minify HTML and render the footer later
  • Lazy load iframes (On): gives other iframes, such as a map or a form, loading="lazy", so the browser loads them when they come near the viewport. An iframe is a whole page with its own scripts, and one further down no longer takes bandwidth from what the visitor sees first. An iframe that already has a loading attribute is left alone, so give a map at the top of the page loading="eager".
  • Lazy load iframes with JavaScript (Off): moves each iframe's address into data-src and puts it back with a small script when the iframe comes into view. It's for browsers without native lazy loading, and current browsers all have it. With it on, an iframe stays empty for a visitor whose JavaScript doesn't run, so leave it off.
  • Minify HTML (On): removes whitespace and comments from the HTML before the page is cached, so every page is a little smaller. Turn it off if invalid HTML breaks your layout, or when you need the HTML comments in the page source, for instance while you debug another plugin.
  • Render the footer later (Off): adds content-visibility: auto to the footer, so the browser skips laying it out and painting it until the visitor scrolls near it. That's rendering work saved while the page loads, worth trying on a footer full of menus and widgets. It does nothing until you fill in Footer selector, for example with footer.
  • Footer selector (Empty): the element Render the footer later works on, written as one simple selector such as footer or .site-footer. An #id works too. The first element on the page that matches gets it.

When to turn speculation down

A prerendered page runs its JavaScript, analytics included. Google Analytics 4 waits until the page is shown before it counts it; a script that doesn't wait counts a page view for every prerendered page nobody opened. If your page views jump after you install the plugin, this is the first thing to check. Choose Custom with prefetch, or fix the script.

When your host charges per request, or most links lead to pages the cache skips, choose WordPress or Off. And 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 straight from the cache.

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.