Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module Proposal: Speculation prerendering & prefetching with the Speculation Rules API #897

Closed
Tracked by #908
felixarntz opened this issue Dec 5, 2023 · 1 comment
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules)

Comments

@felixarntz
Copy link
Member

felixarntz commented Dec 5, 2023

Overview

  • Proposed module name: Speculation Rules
  • Proposed module slug: speculation-rules
  • Proposed module owner GitHub username(s): felixarntz

About the module

Purpose

The Speculation Rules API is a relatively new browser API which allows "speculative" prefetching and prerendering. Historically, prefetching and prerendering has only been possible for specific "hard-coded" resources, which in reality is often difficult or even unrealistic to get right across an ever-changing website. The Speculation Rules API allows sites to define certain rules to dynamically prefetch and prerender certain resources, e.g. when the user hovers over or clicks on a link to another URL.

This proposed module enables prefetching and prerendering with the new API. The necessary API capabilities will only become publicly available in Chrome 121 (likely January 2024), and right now they can be used with an origin trial (see #733). As such, the plan is to develop this module in a feature branch and only launch it once the feature is rolled out publicly and once the minimum requirements agreed for the module on have been implemented.

Scope

  • The module should prerender frontend URLs on hover by default.
  • Certain URLs should be excluded from this behavior (e.g. wp-login.php, or anything in wp-admin). This list should be customizable so that plugins that implement more dynamic capabilities on certain URLs can exclude those as well.
  • UI controls should be provided in WP Admin to change the behavior to prefetch URLs instead of prerendering, and another one to change the behavior from prefetching/prerendering on hover to only do it on click.
    • Both alternatives are less beneficial from a performance perspective, but potentially preferable for other reasons: For example, prerendering can be problematic with dynamic content, and relying on hover can result in wastefully loaded pages, if the user doesn't actually end up navigating there.
    • As this is a Performance Lab module, it makes sense with the more performant setting by default. For a potential future WordPress core proposal, the default would have to be determined based on user feedback, and UI controls would most likely not be part of the WordPress core implementation. For early feedback, they are crucial though to make it easy to experiment with different configurations.
  • It should be possible for certain URLs to only be excluded from prerendering, but not from prefetching. In other words, if the site is configured to prerender, those URLs would fall back to prefetching. If the site is configured to prefetch, those URLs would just work like any other.

The first two points above are already being implemented in #733. The remaining points would be implement in follow up pull requests against the feature branch feature/speculationrules.

Rationale

WordPress has supported prefetching and prerendering via link tags for several years, however using those tags correctly is difficult. It is furthermore challenging from an ecosystem perspective: For instance, if every plugin was going to add their resources to be prefetched or prerendered, it would eventually defeat the purpose (if everything is a priority, nothing is a priority). A more objective, rule based approach like one the Speculation Rules API offers makes more sense. As described above, such a dynamic approach is also easier to use and has the potential to unlock prefetching and prerendering capabilities for a large part of the WordPress ecosystem and the overall web.

Other

Learn more about the Speculation Rules API:

@felixarntz felixarntz changed the title Module Proposal: Module Proposal: Speculation prerendering & prefetching with the Speculation Rules API Dec 6, 2023
@felixarntz
Copy link
Member Author

Fixed via #733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules)
Projects
No open projects
Development

No branches or pull requests

1 participant