-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add speculative loading support #7860
Add speculative loading support #7860
Conversation
… of setting, with expanded test coverage.
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
… and disable speculative loading by default entirely when not using pretty permalinks.
…s root directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some small comments on the PR, but overall I think this looks great. I commented on the Trac ticket with some bigger picture questions/suggestions. But the PR itself seems good pending those being answered.
Co-authored-by: Jonathan Desrosiers <[email protected]>
…/wordpress-develop into add/62503-speculative-loading
…line inline comments.
@desrosj Based on what we discussed and your related point in https://core.trac.wordpress.org/ticket/62503#comment:15, I have updated the PR in a9c52f8 to disallow use of This is in line with the plugin that has never supported |
tests/phpunit/tests/speculative-loading/wpIsValidSpeculationRulesEagerness.php
Outdated
Show resolved
Hide resolved
@felixarntz I have just a few questions on the technical approach here before diving too deep into nitpicking, as overall I think this looks pretty good.
|
I'm not sure about the value of doing that. I'm not opposed, but I also don't see a benefit to it in terms of future compat. Both would be public globally available methods, so I think the future compat burden would be similar either way. I went with the functions based on how WordPress Core is largely function based. For static methods, I could see maybe the
This relates to my above reply: The
This is present because anyone could call the |
Thanks for explaining your thinking, @felixarntz, particularly conceptually how you see the For now, my main criticism is about how the
Is there a use case you have in mind where someone would want to use this function to generate a I do think that the validation helpers conceptually fit better as methods on the class, as they are all referenced within the In fact, you could even allow a config to be passed to the constructor of the class, which would first validate the config before adding the rule (or rules) to the class, in which case function wp_get_speculation_rules() {
$config = wp_get_speculation_rules_configuration();
// Include any required logic we don't want to be filterable here.
$speculation_rules = new WP_Speculation_Rules( $config );
if ( $speculation_rules->is_valid() ) {
do_action( 'wp_load_speculation_rules', $speculation_rules );
return $speculation_rules;
}
return false;
} |
That's fair. I did it that way for better separation of concerns and making
I think this mixes up multiple concerns and makes the code too messy. The concepts of "speculation rules" and "speculation rules configuration" are separate concepts:
For this distinction, I think intertwining the |
…ead always rely on configuration.
…s on WP_Speculation_Rules.
@joemcgill Based on your feedback, I've updated the PR: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @felixarntz, the new changes address my main concerns and I'm happy with this approach for an initial commit.
tests/phpunit/tests/speculative-loading/wpPrintSpeculationRules.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpPrintSpeculationRules.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Mukesh Panchal <[email protected]>
…/wordpress-develop into add/62503-speculative-loading
Hi just notice that the performance number on GHA shows some regression https://github.com/WordPress/wordpress-develop/actions/runs/13400657032 |
@mukeshpanchal27 Which specific metric(s) are you referring to? |
@mukeshpanchal27 Just pinging again for clarification to make sure we can ideally address this prior to Beta 1, if necessary. |
Single Site Default summaryHomepage › Theme: twentytwentyone, Locale: en_US
Homepage › Theme: twentytwentyone, Locale: de_DE
The classic theme shows some regression in |
This PR adds speculative loading support to WordPress Core, as outlined in the Trac ticket:
wp_get_speculation_rules_configuration()
to get the current speculation rules configuration (consisting of "mode" and "eagerness").auto
, which later is evaluated into whatever the current Core default is. For the initial implementation at least, that default is to "prefetch" with "conservative" eagerness.wp_speculation_rules_configuration
can be used to override the behavior, either to change it to something more eager, or to hard-code it to the current default to force-control it, even if Core's default should change in the future.wp_get_speculation_rules()
to compute the full data for speculation Rules JSON output, based on the given configuration (return value fromwp_get_speculation_rules_configuration()
). This function is mostly a copy of the plugin'splsr_get_speculation_rules()
function./wp-admin/*
,/wp-*.php
, etc which should never be speculatively loaded.wp_speculation_rules_href_exclude_paths
can be used to add further URL patterns to exclude, relevant for plugins that may want to customize this. This filter receives the mode (prefetch
orprerender
) as context, which thus allows to add exclusions depending on which mode is currently used.no-prefetch
class on their anchor, as well as excludes prerendering links that use ano-prerender
class.wp_print_speculation_rules()
which is hooked intowp_footer
to print the default speculation rules JSON, unless thewp_get_speculation_rules_configuration()
returnsnull
to indicate that speculative loading is disabled.WP_URL_Pattern_Prefixer
, which is a direct port of the plugin'sPLSR_URL_Pattern_Prefixer
class that handles safe prefixing of URL patterns with WordPress base paths (like home URL, site URL, plugins directory URL etc.).Trac ticket: https://core.trac.wordpress.org/ticket/62503
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.