Consider a deeper integration with speculation rules api

Created on 16 May 2024, 7 months ago

Problem/Motivation

During Google I/O 2024 there was a great presentation on the Speculation Rules API
https://youtu.be/bSua9vMdrNM

During the talk this sample code was shown: (composited from two code samples during the video)

<script type="speculationrules">
  {
    "prerender": [{
      "where": {
        "and": [
          { "href_matches: "/*" },
          { "not": {"href_matches": "/wp-admin"}},
          { "not": {"selector_matches": ".do-not-prerender"}},
          { "not": {"selector_matches": "[rel=nofollow]"}}
        ]
      },
      "eagerness": "moderate"
    }]
  }

With the Speculation Rules API working in your browser what this would do is prerender the first 10 links that have opt-ed out of prerendering (through the use of the class or nofollow) or is an administrative link (for the hypothetical Wordpress site), but only when the user hovers (or click down event) their mouse on the link.

The API also provides:

  • Conservative mode: prerender on mouse/pointer down (so like the moment before a click)
  • Eager mode: prerender on page load

The impact of this change is to get as close to instant loading of pages as possible. As I mentioned above there appear to be some built-in limitations of the prerendering. These ultimatley make sense when you consider that you might arrive on a page with 100s of links. You don't want them all to prefetch + prerender. That would be a lot of traffic caused by a single page view.

All that said, I wonder if this module can adapt to the new API? What I think would be needed is:

    Either a means of gathering all the links a path has
    or some common sense regular expressions that would cover most scenarios

If option 2 is possible, maybe someday we wouldn't actually need a module it could just be part of a theme that is extended.

Proposed resolution

Gauge interest in this idea
Plan Next Steps

Remaining tasks

Let's chat through the details here or in slack.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024