Skip to content

Oxyplug/oxy-prefetch

Repository files navigation

Oxyplug Prefetch & Prerender

Faster next-page loads by prefetching and prerendering links using the browser's native Speculation Rules API. It improves perceived performance, UX, and Core Web Vitals.

WordPress PHP License Version

⚠️ Speculation Rules are supported only on Chromium-based browsers (v121+). Other browsers simply ignore the rules — no errors, no fallback needed.


Features

  • Immediate prefetch — automatically prefetch the first N items on post/product/category listing pages (default 4, configurable).
  • Immediate prerender — fully prerender the first N listing items, like an invisible background tab (default 3, configurable).
  • Hover (moderate) prefetch/prerender — speculate a destination when the user hovers a link, just before the click.
  • Per-post custom URLs — specify exact URLs to prefetch/prerender from a given post, product, or page via a metabox.
  • Exclusions — skip URLs by path, with RegEx-style href_matches patterns for hover mode, plus a selector_matches CSS opt-out (.no-prefetch / .no-prerender / rel="nofollow").
  • Safe by default — state-changing GET links (login, admin, comments, checkout/my-account, add-to-cart, nonce-bearing URLs) are excluded out of the box.
  • WordPress 6.8 core-aware — integrates with core Speculative Loading and suppresses core's block when active to avoid duplicate rules.
  • No-Vary-Search — one entry can match URLs differing only by tracking/sort query params.
  • Configurable eagernessconservative / moderate / eager per feature.

Prefetch vs. Prerender

What it does Cost Best for
Prefetch Downloads the next page's document only Low Broad coverage of likely-next links
Prerender Fully renders the next page in the background Higher A small number of very-likely next pages

Requirements

  • WordPress 5.3+
  • PHP 7.4+
  • A Chromium-based browser (v121+) on the visitor side to benefit from speculation

Installation

From source

  1. Download or clone this repository into your wp-content/plugins/ directory:
    git clone https://github.com/Oxyplug/oxy-prefetch.git wp-content/plugins/oxyplug-prefetch
  2. Activate Oxyplug Prefetch & Prerender from the WordPress Plugins screen.
  3. Configure under Tools → Oxyplug Prefetch & Prerender.

Building the admin assets (optional)

The Material Design 3 admin components are bundled in assets/js/dist/. To rebuild them:

npm install
npm run build

Usage

  1. Go to Tools → Oxyplug Prefetch & Prerender.
  2. Enable and tune:
    • Prefetch — number of immediate prefetches, and/or hover prefetch.
    • Prerender — number of immediate prerenders, and/or hover prerender.
    • Exclusion — paths to skip (RegEx allowed for hover mode).
  3. On any post/page/product edit screen, use the Oxyplug Prefetch & Prerender metabox to add custom URLs to prefetch/prerender when that page is viewed.

Exclusion examples

Pattern Effect
/logout Excludes the logout path
/(page1|page2)/ Excludes URLs starting with page1 or page2
/custom_pages/* Excludes anything under custom_pages

How it works

On the front end the plugin emits one or more <script type="speculationrules"> blocks in the footer:

  • Immediate rules use a list source built from the current query's first N permalinks (and any per-post custom URLs).
  • Moderate rules use a document source with a configurable eagerness, matching /* and excluding the configured paths and state-changing links via not → href_matches / not → selector_matches, with optional expects_no_vary_search.

On WordPress 6.8+, the plugin detects core's own Speculative Loading: it feeds its default exclusions into core and, when any of its features are enabled, suppresses core's block so the page never ships two competing rule sets.

Development

Lint locally:

php -l oxy-prefetch.php
node --check assets/js/admin-script.js

Changelog

See readme.txt for the full changelog. Latest:

3.1.0

  • Integrate with WordPress core Speculative Loading (WP 6.8+): feed default exclusions into core and suppress core output when the plugin's features are active, to avoid duplicate/competing rule sets
  • Add No-Vary-Search support so prefetch/prerender entries still match URLs that differ only by tracking/sort query params (configurable param list)
  • Make eagerness (conservative / moderate / eager) configurable per feature for prefetch and prerender
  • Broaden default exclusions to protect state-changing GET links (wp-login.php, wp-admin, comments, checkout/my-account, add-to-cart, remove_item, undo_item, _wpnonce, _wp_http_referer)
  • Add CSS opt-out via selector_matches (.no-prefetch / .no-prerender / .no-speculation and rel="nofollow")
  • Add a prerender + analytics caveat note in the settings UI
  • Add oxy_prefetch_immediate_rules / oxy_prefetch_moderate_rules filters (e.g. to deliver rules via the Speculation-Rules HTTP header) and exclusion filters
  • Tested up to WordPress 6.8

3.0.2

  • Add str_starts_with() polyfill for PHP 7.4 compatibility
  • Fix same-host validation for custom prefetch/prerender URLs
  • Add capability checks to settings and notice AJAX handlers
  • Use wp_update_post() instead of direct DB writes
  • Add uninstall cleanup of options, transients, and post meta
  • Load admin assets only on relevant screens
  • Tested up to WordPress 7.0

Links

License

GPLv2 or later — © Oxyplug

About

WordPress plugin that speeds up next-page loads by prefetching and prerendering links via the browser's native Speculation Rules API, improving UX and Core Web Vitals.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors