Speculative Loading
Description
This plugin adds support for the 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, but it only prefetches with conservative eagerness by default. In contrast, this plugin defaults to prerendering with moderate eagerness 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, 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. Alternatively, you can add the no-prerender CSS class to any link that should not be prerendered. See FAQ for more information.
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.
Other Notable Features
Here are a few other notable features of this free Speculative Loading plugin.
FAQ
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:
<?php add_filter( 'plsr_speculation_rules_href_exclude_paths', function ( array $exclude_paths ): array { $exclude_paths[] = '/cart/*'; return $exclude_paths; } ); Keep in mind that sometimes it may be useful to exclude a URL from prerendering while still allowing it to be prefetched. For example, a page with client-side JavaScript to update user state should probably not be prerendered, but it would be reasonable to prefetch.
For this purpose, the plsr_speculation_rules_href_exclude_paths filter receives the current mode (either “prefetch” or “prerender”) to provide conditional exclusions.
The following example ensures that URLs like https://example.com/products/... cannot be prerendered, while still allowing them to be prefetched:
<?php add_filter( 'plsr_speculation_rules_href_exclude_paths', function ( array $exclude_paths, string $mode ): array { if ( 'prerender' === $mode ) { $exclude_paths[] = '/products/*'; } return $exclude_paths; }, 10, 2 ); As mentioned above, adding the no-prerender CSS class to a link will prevent it from being prerendered (but not prefetched). Additionally, links with rel=nofollow will neither be prefetched nor prerendered because some plugins add this to non-idempotent links (e.g. add to cart); such links ideally should rather be buttons which trigger a POST request or at least they should use wp_nonce_url().
Contributors and developers
“Speculative Loading” is open source software. The following people have contributed to this plugin.
WPS
6.65
Average
Ratings
5 out of 5 | 18Version
1.6.0Last updated
3 months agoActive installations
70,000+WordPress version
6.9.1 or higherPHP version
7.2 or higherLanguages
15Tags
Javascript,Performance,Prefetch,Prerender,Speculation RulesOther plugins you might like
LiteSpeed Cache
By LiteSpeed Technologies
WPS
7.76
Very Good
2.7k+reviews
active installation
Tested with
6.9.1Imagify Image Optimization – Optimize Images | Compress Images | Convert WebP | Convert AVIF
By WP Media
WPS
7.41
Very Good
1.6k+reviews
active installation
Tested with
6.9.1Image Optimizer – Optimize Images and Convert to WebP or AVIF
By Elementor
WPS
6.67
Average
70+reviews
active installation
Tested with
6.9.1EWWW Image Optimizer
By nosilver4u
WPS
7.42
Very Good
1.8k+reviews
active installation
Tested with
6.9.1Smush Image Optimization – Optimize Images | Compress & Lazy Load Images | Convert WebP & AVIF | Image CDN
By WPMU DEV - Your All-in-One WordPress Platform
WPS
7.4
Very Good
6k+reviews
active installation
Tested with
6.9.1WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance
By David Anderson / Team Updraft
WPS
7.39
Very Good
2.6k+reviews
active installation
Tested with
6.9.1