Speculatr for Craft CMS

Free · Craft CMS 5

The next page, loaded before the click

Chromium browsers will happily fetch — or fully render — the page a reader is about to open, if you tell them which links are safe to open early. The telling is a small JSON document. The safety is the entire problem.

Speculatr

A prerender does not fetch a page. It runs one

That is the whole reason this is a plugin rather than a snippet. Point a naive rule at every link and it eventually opens the one that signs somebody out — from a hidden tab, before anybody clicked. So Speculatr assembles the exclusions first, and it assembles them out of Craft's own configuration rather than from a list of guesses.

json
{
  "prerender": [{
    "source": "document",
    "where": { "and": [
      { "href_matches": "/*", "relative_to": "document" },

      // read out of your Craft config, under whatever
      // names this site gives them
      { "not": { "href_matches": "/admin" } },
      { "not": { "href_matches": "/admin/*" } },
      { "not": { "href_matches": "/actions/*" } },
      { "not": { "href_matches": "/*\\?*(^|&)action=*" } },
      { "not": { "href_matches": "/logout" } },
      { "not": { "href_matches": "/*\\?*(^|&)token=*" } },

      { "not": { "selector_matches": ".no-speculation" } },
      { "not": { "selector_matches": "[rel~=nofollow]" } }
    ]},
    "eagerness": "moderate"
  }]
}

Features

One feature that makes pages instant, and five that make the first one safe to leave on.

It asks Craft, not a list

The WordPress equivalent can hard-code /wp-admin. Craft's equivalents are all configurable, so Speculatr reads them out of your own config: the control-panel trigger, the action trigger, every account path, and the preview, site and CSRF token parameters. A site that moved its control panel — or renamed its logout — is covered without anybody remembering to say so.

Prefetch, prerender, or both at once

A prefetch downloads the HTML and stops: a few kilobytes, nothing runs. A prerender loads and executes the whole page in a hidden tab, so the navigation is genuinely instant. Run both and they layer — the browser prefetches on hover and upgrades to a prerender only once the reader commits, so the expensive half is never spent on a link the pointer merely crossed.

Signed-in visitors are the risky ones

A personalised page is both the most expensive one you serve and the likeliest to have something on it that should not happen twice. So signed-in users are off by default, admins are their own switch — try it on yourself first — and when you do turn them on, prerendering degrades to prefetching rather than running their page in a hidden tab.

Campaign links still hit the cache

A prefetch of /pricing is no use if the reader arrives at /pricing?utm_source=newsletter. Speculatr sends a No-Vary-Search header on your pages and mirrors it into the rules: the header is what makes the cached entry match, the rule is what stops the browser racing its own in-flight prefetch. Both halves, because either one alone does nothing.

A checker that names the reason

The question nobody asks is “what are my rules”. The question everybody asks is whether it is going to prerender the thing that signs people out. Paste a URL into the control panel — or run speculatr/rules/check on the command line — and it tells you, names the exclusion that stopped it, and admits what a URL on its own cannot settle.

Nothing stored, nothing sent

No database tables, no migrations, no cookies, no build step, and not one outbound HTTP request. The plugin's entire output is a script element and two response headers. Uninstall it and your pages are exactly what they were, with nothing left behind to clean up.

Frequently Asked Questions

The questions worth answering before you switch it on.

Free, and it stays free

No editions, no licence key, no trial. Install it, and the next page your readers open is already loading.