=== Speculative Loading === Contributors: wordpressdotorg Tested up to: 6.8 Stable tag: 1.6.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, javascript, speculation rules, prerender, prefetch Enables browsers to speculatively prerender or prefetch pages to achieve near-instant loads based on user interaction. == Description == This plugin adds support for the [Speculation Rules API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API), which allows defining rules by which certain URLs are dynamically prefetched or prerendered. This core Speculative Loading functionality was [merged into WordPress 6.8](https://make.wordpress.org/core/2025/03/06/speculative-loading-in-6-8/), but it only prefetches with conservative eagerness by default. In contrast, this plugin defaults to prerendering with moderate eagerness (i.e. when interacting with a link), and it provides a user interface to customize the mode and eagerness via the "Speculative Loading" section on the _Settings > Reading_ admin screen. By default, speculative loading is only enabled for logged-out users, since unauthenticated pages are typically only eligible for caching and so more efficient to prefetch/prerender. This means that sites with frequent logged-in users on the frontend—such as e-commerce, forums, or membership sites—will not benefit from the feature. If your server can handle the additional load (for example, with persistent object caching), you can opt in to enable speculative loading for all logged-in users or for administrators only. This setting exclusively affects frontend pages; admin screens are always excluded. A filter can be used to exclude certain URL paths from being eligible for prefetching and prerendering (see FAQ section). Alternatively, you can add the `no-prerender` CSS class to any link (`` tag) that should not be prerendered. See FAQ for more information. = Browser support = The Speculation Rules API is a new web API, and the functionality used by the plugin is supported in Chromium-based browsers such as Chrome, Edge, or Opera using version 121 or above. Other browsers such as Safari and Firefox will ignore the functionality with no ill effects; they will simply not benefit from the speculative loading. Note that certain browser extensions may disable preloading by default. * [Browser support for the Speculation Rules API in general](https://caniuse.com/mdn-html_elements_script_type_speculationrules) * [Information on document rules syntax support used by the plugin](https://developer.chrome.com/docs/web-platform/prerender-pages) _This plugin was formerly known as Speculation Rules._ == Installation == = Installation from within WordPress = 1. Visit **Plugins > Add New**. 2. Search for **Speculative Loading**. 3. Install and activate the **Speculative Loading** plugin. = Manual installation = 1. Upload the entire `speculation-rules` folder to the `/wp-content/plugins/` directory. 2. Visit **Plugins**. 3. Activate the **Speculative Loading** plugin. = After activation = 1. Visit the **Settings > Reading** admin screen. 2. Use the controls in the **Speculative Loading** section to configure speculative loading. == Frequently Asked Questions == = How can I prevent certain URLs from being prefetched and prerendered? = Not every URL can be reasonably prerendered. Prerendering static content is typically reliable, however prerendering interactive content, such as a logout URL, can lead to issues. For this reason, certain WordPress core URLs such as `/wp-login.php` and `/wp-admin/*` are excluded from prefetching and prerendering. Additionally, any URLs generated with `wp_nonce_url()` (or which contains the `_wpnonce` query var) and `nofollow` links are also ignored. You can exclude additional URL patterns by using the `plsr_speculation_rules_href_exclude_paths` filter. The following example ensures that URLs like `https://example.com/cart/` or `https://example.com/cart/foo` are excluded from prefetching and prerendering: ` ` element from the page using standard JavaScript DOM APIs should this be needed when state changes without a new page load. = Where can I submit my plugin feedback? = Feedback is encouraged and much appreciated, especially since this plugin may contain future WordPress core features. If you have suggestions or requests for new features, you can [submit them as an issue in the WordPress Performance Team's GitHub repository](https://github.com/WordPress/performance/issues/new/choose). If you need help with troubleshooting or have a question about the plugin, please [create a new topic on our support forum](https://wordpress.org/support/plugin/speculation-rules/#new-topic-0). = Where can I report security bugs? = The Performance team and WordPress community take security bugs seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. To report a security issue, please visit the [WordPress HackerOne](https://hackerone.com/wordpress) program. = How can I contribute to the plugin? = Contributions are always welcome! Learn more about how to get involved in the [Core Performance Team Handbook](https://make.wordpress.org/performance/handbook/get-involved/). == Changelog == = 1.6.0 = **Enhancements** * Add Speculative Loading opt-in for authenticated requests. ([2097](https://github.com/WordPress/performance/pull/2097)) * Add warning notice to Speculative Loading setting for authenticated users when persistent object cache is not present. ([2144](https://github.com/WordPress/performance/pull/2144)) * Update Speculative Loading readme description to note purpose after core merge. ([2120](https://github.com/WordPress/performance/pull/2120)) = 1.5.0 = **Enhancements** * Add support for Speculative Loading WP Core API, loading the plugin's own API implementation conditionally. ([1883](https://github.com/WordPress/performance/pull/1883)) = 1.4.0 = **Enhancements** * Implement speculative loading considerations for safer behavior. ([1784](https://github.com/WordPress/performance/pull/1784)) = 1.3.1 = **Bug Fixes** * Check if rel contains nofollow instead of being just nofollow when excluding speculative loading. ([1232](https://github.com/WordPress/performance/pull/1232)) = 1.3.0 = **Enhancements** * Prevent speculatively loading links to the uploads, content, plugins, template, or stylesheet directories. ([1167](https://github.com/WordPress/performance/pull/1167)) * Facilitate embedding Speculative Loading in other plugins/themes. ([1159](https://github.com/WordPress/performance/pull/1159)) * Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) * Bump minimum PHP requirement to 7.2. ([1130](https://github.com/WordPress/performance/pull/1130)) = 1.2.2 = **Bug Fixes** * Fix composition of href exclude paths to account for JSON encoding and differing site/home URLs. ([1164](https://github.com/WordPress/performance/pull/1164)) **Documentation** * Update readme with browser support and FAQ section about analytics and personalization. ([1155](https://github.com/WordPress/performance/pull/1155)) = 1.2.1 = **Enhancements** * Add settings link to Speculative Loading plugin action links. ([1145](https://github.com/WordPress/performance/pull/1145)) * Bump minimum PHP version to 7.2. ([1130](https://github.com/WordPress/performance/pull/1130)) **Bug Fixes** * Exclude _wpnonce URLs in speculation rules. ([1143](https://github.com/WordPress/performance/pull/1143)) * Exclude rel=nofollow links from prefetch/prerender. ([1142](https://github.com/WordPress/performance/pull/1142)) = 1.2.0 = * Add missing uninstall.php to remove plugin's database option. ([1128](https://github.com/WordPress/performance/pull/1128)) = 1.1.0 = * Allow excluding URL patterns from prerendering or prefetching specifically. ([1025](https://github.com/WordPress/performance/pull/1025)) * Rename plugin to "Speculative Loading". ([1101](https://github.com/WordPress/performance/pull/1101)) * Add Speculative Loading generator tag. ([1102](https://github.com/WordPress/performance/pull/1102)) * Bump minimum required WP version to 6.4. ([1062](https://github.com/WordPress/performance/pull/1062)) * Update tested WordPress version to 6.5. ([1027](https://github.com/WordPress/performance/pull/1027)) = 1.0.1 = * Escape path prefix and restrict it to be a pathname in Speculation Rules. ([951](https://github.com/WordPress/performance/pull/951)) * Force HTML5 script theme support when printing JSON script. ([952](https://github.com/WordPress/performance/pull/952)) * Add icon and banner assets for plugin directory. ([987](https://github.com/WordPress/performance/pull/987)) = 1.0.0 = * Initial release of the Speculative Loading plugin as a standalone plugin. ([733](https://github.com/WordPress/performance/pull/733))