-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: trunk
Are you sure you want to change the base?
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.
$base_href_exclude_paths = array( | ||
$prefixer->prefix_path_pattern( '/wp-*.php', 'site' ), | ||
$prefixer->prefix_path_pattern( '/wp-admin/*', 'site' ), | ||
$prefixer->prefix_path_pattern( '/*', 'uploads' ), |
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.
could we exclude wp-content/*
instead of each of these individual paths (unless they were in non-standard locations without the wp-content prefix)?
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.
The /wp-*.php
and /wp-admin/*
paths aren't actually within wp-content
. Note that the wp-content
directory is already excluded, see line 162.
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 suppose the uploads path is excluded separately because it's not necessarily under wp-content
, right?
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.
Yeah, same with plugins and themes. 99% of times they should be within wp-content
, but not guaranteed.
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.
Plugins/themes/uploads - If they are in wp-content (which is quick to check) we don't need extra entries for them.
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.
True, but it also doesn't hurt.
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.
Agreed it doesn't hurt, checking for that would likely be more expensive to do than including the extra rules unconditionally.
/** | ||
* Tests speculation rules output with prefetch for the different eagerness levels. | ||
* | ||
* @ticket 62503 |
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.
All of these repeating @ticket 62503
annotations seem excessive/extraneous. @ticket
annotations are mostly used to run a set of tests while working on a ticket AFAIK. We can already run all of the tests for this ticket using --group= speculative-loading
so we can remove all of the @ticket
annotations entirely, right?
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 don't think they exist temporarily. They're useful for context, makes it easy to find out as part of which ticket a test was added. Of course right now @ticket 62503
is synonymous with @group speculative-loading
, but this will no longer be the case in the near future, as soon as any enhancement or bug is fixed via another ticket.
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 always understood @ticket
as something to be used when adding regression tests for bugs, not enhancements. Also not a fan of adding @ticket
everywhere for a new feature like this. But I know some people do that, so 🤷
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.
Looks good! left some small feedback/question.
tests/phpunit/tests/speculative-loading/wpUrlPatternPrefixer.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpGetSpeculationRulesConfiguration.php
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpGetSpeculationRulesConfiguration.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpIsValidSpeculationRulesEagerness.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpIsValidSpeculationRulesMode.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpUrlPatternPrefixer.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpUrlPatternPrefixer.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/speculative-loading/wpGetSpeculationRules.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Pascal Birchler <[email protected]>
…/wordpress-develop into add/62503-speculative-loading
@swissspidy Feedback applied! |
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.