Skip to content

Add support for prerender_until_script mode and origin trial token#2512

Open
danielpazwp wants to merge 1 commit into
WordPress:trunkfrom
danielpazwp:add/prerender-until-script
Open

Add support for prerender_until_script mode and origin trial token#2512
danielpazwp wants to merge 1 commit into
WordPress:trunkfrom
danielpazwp:add/prerender-until-script

Conversation

@danielpazwp

Copy link
Copy Markdown

Summary

Fixes #2362

This pull request adds support for the experimental prerender_until_script speculation rules mode, which serves as a middle ground between prefetching and full prerendering (downloading resources and starting layout but pausing before running blocking script elements).

It also adds native support for configuring the Google Chrome Origin Trial token for this feature, allowing site owners to test it in production with real visitors.

Relevant technical choices

  • Mode Allowlist & Speculation Rules Class: Added prerender_until_script to the allowed mode list ($mode_allowlist) in the Core speculation rules API and updated relevant Docblocks.
  • Target Exclusions: Updated the default speculation rule filters. When using prerender_until_script, we automatically apply exclusions for links marked with .no-prefetch (since prefetching is part of prerendering) and .no-prerender (since prerendering until script is a form of prerendering).
  • Origin Trial Settings Field: Added a new setting field origin_trial_token to the Speculative Loading settings section under Settings > Reading. The token is sanitized using sanitize_text_field().
  • Header Meta Tag Injection: Added the plsr_print_origin_trial_meta_tag() hook callback to wp_head at priority 1 to output <meta http-equiv="origin-trial" content="..."> as early as possible in the head tag, but only if a token is configured, speculative loading is enabled, and the speculation mode is set to prerender_until_script.

How to test

1. Enable the Experimental Chrome Flag (Local testing)

Since this feature is not yet fully enabled by default in all Chrome versions, you must enable the flag locally:

  1. Open Google Chrome and go to chrome://flags/#prerender-until-script.
  2. Change the setting to Enabled and relaunch your browser.

2. Configure WordPress Settings

  1. Go to your WordPress admin panel under Settings > Reading.
  2. Under the Speculative Loading section, change the Speculation Mode to Prerender until script.
  3. (Optional for production tests): Paste a valid Chrome Origin Trial token in the new Origin Trial Token input field.
  4. Save the settings.

3. Verify Frontend Behavior

  1. Open your website frontend in Chrome (make sure you are testing in an Incognito window or have set the User Authentication Status to allow admins).
  2. Inspect the page source code and verify that the <script type="speculationrules"> tag is generated with "prerender_until_script" rules, and (if configured) the <meta http-equiv="origin-trial" content="..."> tag is present in the <head>.
  3. Open Chrome DevTools (F12), go to the Application tab, and select Speculative loads on the left menu.
  4. Hover over a link on the page and verify that the link appears in the Speculations table. The page should load instantly upon click.

Use of AI Tools

This pull request was co-authored using Antigravity (a coding assistant designed by Google DeepMind).

  • To what extent: The AI assistant analyzed the codebase, proposed the implementation plan, refactored the class and plugin files, wrote verification mock scripts to test PHP compilation, and prepared the branch commit message. The final code was manually reviewed, verified, and pushed to GitHub.

@danielpazwp danielpazwp requested a review from westonruter as a code owner June 4, 2026 11:27
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @dpazwp.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: dpazwp.

Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@danielpazwp danielpazwp force-pushed the add/prerender-until-script branch 2 times, most recently from c2d6231 to fb8d261 Compare June 4, 2026 11:59
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.40%. Comparing base (a2815e6) to head (f9a5fbe).
⚠️ Report is 11 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/speculation-rules/hooks.php 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2512      +/-   ##
==========================================
+ Coverage   69.29%   69.40%   +0.10%     
==========================================
  Files          90       90              
  Lines        7723     7753      +30     
==========================================
+ Hits         5352     5381      +29     
- Misses       2371     2372       +1     
Flag Coverage Δ
multisite 69.40% <97.61%> (+0.10%) ⬆️
single 35.84% <61.90%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielpazwp danielpazwp force-pushed the add/prerender-until-script branch from fb8d261 to f9a5fbe Compare June 4, 2026 12:12
@danielpazwp danielpazwp marked this pull request as draft June 4, 2026 12:14
@danielpazwp danielpazwp marked this pull request as ready for review June 4, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explore prerender_until_script mode for Speculative Loading

2 participants