Title: Speculative Loading
Author: WordPress Performance Team
Published: <strong>19 januari 2024</strong>
Last modified: 2 december 2025

---

Sök tillägg

![](https://ps.w.org/speculation-rules/assets/banner-772x250.png?rev=3098224)

![](https://ps.w.org/speculation-rules/assets/icon.svg?rev=3098224)

# Speculative Loading

 Av [WordPress Performance Team](https://profiles.wordpress.org/performanceteam/)

[Ladda ner](https://downloads.wordpress.org/plugin/speculation-rules.1.6.0.zip)

 * [Detaljer](https://sv.wordpress.org/plugins/speculation-rules/#description)
 * [Recensioner](https://sv.wordpress.org/plugins/speculation-rules/#reviews)
 *  [Installation](https://sv.wordpress.org/plugins/speculation-rules/#installation)
 * [Utveckling](https://sv.wordpress.org/plugins/speculation-rules/#developers)

 [Support](https://wordpress.org/support/plugin/speculation-rules/)

## Beskrivning

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 (`<a>` tag) that should not be prerendered. See FAQ for more
information.

#### Stöd för webbläsare

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.

 * [Webbläsarstöd för API:et ”Speculation Rules” i allmänhet](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)

_Detta tillägg hette tidigare Speculation Rules._

## Installation

#### Installation inifrån WordPress

 1. Besök **Tillägg > Lägg till nytt**.
 2. Sök efter **Speculative Loading**.
 3. Installera och aktivera tillägget **Speculative Loading**.

#### Manuell installation

 1. Ladda upp hela mappen `speculation-rules` till katalogen `/wp-content/plugins/`.
 2. Besök **Tillägg**.
 3. Aktivera tillägget **Speculation Loading**.

#### After activation

 1. Visit the **Settings > Reading** admin screen.
 2. Use the controls in the **Speculative Loading** section to configure speculative
    loading.

## Vanliga frågor

### Hur kan jag förhindra att vissa URL:er förhandsladdas och förhandsrenderas?

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.

Följande exempel ser till att URL:er som `https://example.com/cart/` eller `https://
example.com/cart/foo` utesluts från förhandsladdning och förhandsrendering.

    ```
    <?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()`.

### Are there any special considerations for speculative loading behavior?

For safety reasons, the entire speculative loading feature is disabled by default
for logged-in users and for sites that do not use pretty permalinks. The latter 
is the case because plugins often use URLs with custom query parameters to let users
perform actions, and such URLs should not be speculatively loaded. For sites without
pretty permalinks, it is impossible or at least extremely complex to differentiate
between which query parameters are Core defaults and which query parameters are 
custom.

If you are running this plugin on a site without pretty permalinks and are confident
that there are no custom query parameters in use that can cause state changes, you
can opt in to enabling speculative loading via the `plsr_enabled_without_pretty_permalinks`
filter:

    ```
    <?php
    add_filter( 'plsr_enabled_without_pretty_permalinks', '__return_true' );
    ```

### How will this impact analytics and personalization?

Prerendering can affect analytics and personalization.

For client-side JavaScript, is recommended to delay these until the prerender is
activated (for example by clicking on the link). Some solutions (like Google Analytics)
already do this automatically, see [Impact on Analytics](https://developer.chrome.com/docs/web-platform/prerender-pages#impact-on-analytics).
Additionally, cross-origin iframes are not loaded until activation which can further
avoid issues here.

Speculating with the default `moderate` eagerness decreases the risk that the prerendered
page will not be visited by the user and therefore will avoid any side effects of
loading such a link in advance. In contrast, `eager` speculation increases the risk
that prerendered pages may not be loaded. Alternatively, the plugin offers to only
speculate on mouse/pointer down (conservative) which reduces the risk even further
and is an option for sites which are concerned about this, at the cost of having
less of a lead time and so less of a performance gain.

A prerendered page is linked to the page that prerenders it, so personalisation 
may already be known by this point and changes (e.g. browsing other products, or
logging in/out) often require a new page load, and hence a new prerender, which 
will then take these into account. But it definitely is something to be aware of
and test! Prerendered pages can be canceled by removing the speculation rules `<
script>` element from the page using standard JavaScript DOM APIs should this be
needed when state changes without a new page load.

### Var kan jag skicka in min återkoppling om tillägget?

Återkoppling uppmuntras och uppskattas mycket, särskilt eftersom detta tillägg kan
innehålla framtida funktioner för WordPress-kärnan. Om du har förslag eller önskemål
om nya funktioner kan du [skicka in dem som ett ärenden i GitHub-filförvaret för WordPress Performance Team](https://github.com/WordPress/performance/issues/new/choose).
Om du behöver hjälp med felsökning eller har en fråga om tillägget, [skapa ett nytt ämne på vårt supportforum](https://wordpress.org/support/plugin/speculation-rules/#new-topic-0).

### Var kan jag rapportera säkerhetsproblem?

Performance-teamet och WordPress-communityn tar säkerhetsfel på allvar. Vi uppskattar
dina ansträngningar att ansvarsfullt rapportera dina upptäckter och kommer att göra
allt vi kan för att erkänna dina bidrag.

För att rapportera ett säkerhetsproblem, besök [WordPress HackerOne](https://hackerone.com/wordpress)-
programmet.

### Hur kan jag bidra till tillägget?

Bidrag är alltid välkomna! Läs mer om hur du kan engagera dig i [Handboken för Core Performance-team](https://make.wordpress.org/performance/handbook/get-involved/).

## Recensioner

![](https://secure.gravatar.com/avatar/9a91528deeb53161704f4fa1b82687f084fb9ea390704058ffc5a5e2e3578e10?
s=60&d=retro&r=g)

### 󠀁[Very promising and impressive plugin!](https://wordpress.org/support/topic/very-promising-and-impressive-plugin/)󠁿

 [Terry J](https://profiles.wordpress.org/texasbiz/) 16 april 2025

Although I have not tried the plugin on live sites, my testing on 3-4 dev boxes 
leaves me impressed. I can see and feel the speed increase I have a couple of heavy
sites and can see this plugin fitting right into the flow. Will get on it soon 🙂

![](https://secure.gravatar.com/avatar/6ac7c2e9bb1e43d09d87b780c06c09b391a52680c3b1512bcd094176376a1a26?
s=60&d=retro&r=g)

### 󠀁[Does what it needs to do.](https://wordpress.org/support/topic/does-what-it-needs-to-do-50/)󠁿

 [OllieJones](https://profiles.wordpress.org/olliejones/) 1 februari 2025

This works. That’s good.

![](https://secure.gravatar.com/avatar/b74336db946c8d8c3f811c4cdcdc350380f0a869db5674c41ab11151e3d3566c?
s=60&d=retro&r=g)

### 󠀁[Very fast and functional – Thanks for this.](https://wordpress.org/support/topic/very-fast-and-functional-thanks-for-this/)󠁿

 [mrimpact](https://profiles.wordpress.org/mrimpact/) 9 augusti 2024

We have done a lot of testing on WordPress sites and WooCommerce stores. Everything
works beautifully and fast. Thank you very much for this amazing plugin.

![](https://secure.gravatar.com/avatar/39a932effeea71cd4f7f4ff167ea1cca1fd832db475adcc1225327e01ef91b2c?
s=60&d=retro&r=g)

### 󠀁[Seriously Impressive](https://wordpress.org/support/topic/seriously-impressive-2/)󠁿

 [groggy72](https://profiles.wordpress.org/groggy72/) 19 juli 2024 1 svar

I was using another plugin which does a similar job but Speculative Loading appears
to be substantially quicker. Using on about 10 sites and no issues. Thank you

![](https://secure.gravatar.com/avatar/4b04f3868d5d00557a0e117f43262a23de2b023b16cf33e18bf233ecce7e4515?
s=60&d=retro&r=g)

### 󠀁[Interesting and Impressive](https://wordpress.org/support/topic/interesting-and-impressive/)󠁿

 [Hudson Atwell](https://profiles.wordpress.org/hudson-atwell/) 4 juni 2024

Amazing results on install. Will continue to check this one out.

![](https://secure.gravatar.com/avatar/80e914c33cfcb58bb025742ce294e1d12f214079d7e14ac31b35e24477c06eda?
s=60&d=retro&r=g)

### 󠀁[Ein absolut sinnvolles Plugin](https://wordpress.org/support/topic/ein-absolut-sinnvolles-plugin/)󠁿

 [lacoste89](https://profiles.wordpress.org/lacoste89/) 27 maj 2024

Es verkürzt die Ladzeit für einen Benutzer sichtbar, auch wenn im Hintergrund die
Seite gleichschnell geladen wird, so fühlt es sich für einen Benutzer extrem schnell
an.

 [ Läs alla 18 betyg ](https://wordpress.org/support/plugin/speculation-rules/reviews/)

## Bidragsgivare och utvecklare

”Speculative Loading” är programvara med öppen källkod. Följande personer har bidragit
till detta tillägg.

Bidragande personer

 *   [ WordPress Performance Team ](https://profiles.wordpress.org/performanceteam/)
 *   [ WordPress.org ](https://profiles.wordpress.org/wordpressdotorg/)

”Speculative Loading” har översatts till 15 språk. Tack till [översättarna](https://translate.wordpress.org/projects/wp-plugins/speculation-rules/contributors)
för deras bidrag.

[Översätt ”Speculative Loading” till ditt språk.](https://translate.wordpress.org/projects/wp-plugins/speculation-rules)

### Intresserad av programutveckling?

[Läs programkoden](https://plugins.trac.wordpress.org/browser/speculation-rules/),
kika på [SVN-filförvaret](https://plugins.svn.wordpress.org/speculation-rules/) 
eller prenumerera på [utvecklarloggen](https://plugins.trac.wordpress.org/log/speculation-rules/)
via [RSS](https://plugins.trac.wordpress.org/log/speculation-rules/?limit=100&mode=stop_on_copy&format=rss).

## Ändringslogg

#### 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

 * Första utgåvan av tillägget ”Speculative Loading” som ett fristående tillägg.(
   [733](https://github.com/WordPress/performance/pull/733))

## Ideellt tillägg

Detta tillägg är utvecklat och stöds av en community. [Bidra till detta tillägg](https://github.com/WordPress/performance)

## Meta

 *  Version **1.6.0**
 *  Senast uppdaterat **5 månader sedan**
 *  Aktiva installationer **70 000+**
 *  WordPress-version ** 6.6 eller senare **
 *  Testat upp till **6.9.4**
 *  PHP-version ** 7.2 eller senare **
 *  Språk
 * [Chinese (Taiwan)](https://tw.wordpress.org/plugins/speculation-rules/), [English (US)](https://wordpress.org/plugins/speculation-rules/),
   [French (France)](https://fr.wordpress.org/plugins/speculation-rules/), [German](https://de.wordpress.org/plugins/speculation-rules/),
   [Hindi](https://hi.wordpress.org/plugins/speculation-rules/), [Korean](https://ko.wordpress.org/plugins/speculation-rules/),
   [Norwegian (Bokmål)](https://nb.wordpress.org/plugins/speculation-rules/), [Persian](https://fa.wordpress.org/plugins/speculation-rules/),
   [Portuguese (Brazil)](https://br.wordpress.org/plugins/speculation-rules/), [Portuguese (Portugal)](https://pt.wordpress.org/plugins/speculation-rules/),
   [Russian](https://ru.wordpress.org/plugins/speculation-rules/), [Spanish (Chile)](https://cl.wordpress.org/plugins/speculation-rules/),
   [Spanish (Spain)](https://es.wordpress.org/plugins/speculation-rules/), [Swedish](https://sv.wordpress.org/plugins/speculation-rules/),
   [Turkish](https://tr.wordpress.org/plugins/speculation-rules/) och [Vietnamese](https://vi.wordpress.org/plugins/speculation-rules/).
 *  [Översätt till ditt språk](https://translate.wordpress.org/projects/wp-plugins/speculation-rules)
 * Etiketter
 * [javascript](https://sv.wordpress.org/plugins/tags/javascript/)[performance](https://sv.wordpress.org/plugins/tags/performance/)
   [prefetch](https://sv.wordpress.org/plugins/tags/prefetch/)[prerender](https://sv.wordpress.org/plugins/tags/prerender/)
 *  [Avancerad vy](https://sv.wordpress.org/plugins/speculation-rules/advanced/)

## Betyg

 5 av 5 stjärnor.

 *  [  18 5-stjärniga recensioner     ](https://wordpress.org/support/plugin/speculation-rules/reviews/?filter=5)
 *  [  0 4-stjärniga recensioner     ](https://wordpress.org/support/plugin/speculation-rules/reviews/?filter=4)
 *  [  0 3-stjärniga recensioner     ](https://wordpress.org/support/plugin/speculation-rules/reviews/?filter=3)
 *  [  0 2-stjärniga recensioner     ](https://wordpress.org/support/plugin/speculation-rules/reviews/?filter=2)
 *  [  0 1-stjärniga recensioner     ](https://wordpress.org/support/plugin/speculation-rules/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/speculation-rules/reviews/#new-post)

[Se alla recensioner](https://wordpress.org/support/plugin/speculation-rules/reviews/)

## Bidragande personer

 *   [ WordPress Performance Team ](https://profiles.wordpress.org/performanceteam/)
 *   [ WordPress.org ](https://profiles.wordpress.org/wordpressdotorg/)

## Support

Har du något att säga? Behöver du hjälp?

 [Visa supportforum](https://wordpress.org/support/plugin/speculation-rules/)