mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Introduce fetchpriority
for Scripts and Script Modules
#8815
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
Open
westonruter
wants to merge
15
commits into
WordPress:trunk
Choose a base branch
from
westonruter:trac-61734
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dbcd32c
Output script modules with fetchpriority=low
westonruter 5207c27
Fix duplicate array keys in data_special_chars_script_encoding
westonruter 088366d
Add ability to set fetch priority for script modules
westonruter 9eab85d
Add fetchpriority support for non-module scripts
westonruter d9c4037
Set fetchpriority=low on comment-reply script
westonruter 4f82a4f
Use auto as default fetchpriority for script modules
westonruter f2cd9be
Avoid printing fetchpriority attribute when auto
westonruter ff4fd36
fixup! Use auto as default fetchpriority for script modules
westonruter 9edbe4c
Use HTML Tag Processor to parse import map
westonruter 021fe74
Ensure parity in args between class methods and global function aliases
westonruter 34ef7fa
Use fetch priority low by default for Interactivity API view script m…
westonruter e54274a
Add missing since tag
westonruter cc1d909
Account for full block.json schema when checking for interactivity
westonruter 4197eb2
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 74a49e1
Remove PHPStan annotations for commit
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,11 +175,21 @@ function register_block_script_module_id( $metadata, $field_name, $index = 0 ) { | |
$block_version = isset( $metadata['version'] ) ? $metadata['version'] : false; | ||
$module_version = isset( $module_asset['version'] ) ? $module_asset['version'] : $block_version; | ||
|
||
$args = array(); | ||
if ( | ||
( isset( $metadata['supports']['interactivity'] ) && true === $metadata['supports']['interactivity'] ) || | ||
( isset( $metadata['supports']['interactivity']['interactive'] ) && true === $metadata['supports']['interactivity']['interactive'] ) | ||
) { | ||
// TODO: Add ability for the fetchpriority to be specified in block.json for the viewScriptModule. In wp_default_script_modules() the fetchpriority defaults to low since server-side rendering is employed for core blocks, but there are no guarantees that this is the case for non-core blocks. That said, viewScriptModule entails Interactivity API, following the pattern from core it _should_ be SSR'ed and that is why this is the default for when the block supports interactivity. | ||
$args['fetchpriority'] = 'low'; | ||
} | ||
|
||
wp_register_script_module( | ||
$module_id, | ||
$module_uri, | ||
$module_dependencies, | ||
$module_version | ||
$module_version, | ||
$args | ||
); | ||
|
||
return $module_id; | ||
|
@@ -243,6 +253,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { | |
$script_args = array(); | ||
if ( 'viewScript' === $field_name && $script_uri ) { | ||
$script_args['strategy'] = 'defer'; | ||
// TODO: There needs to be a way to specify that a script defined in a module is safe to use fetchpriority=low. Perhaps the viewScript should not only allow a handle string or a `file:./foo.js` string, but allow an an array of params like { "href": "./foo.js", "fetchpriority": "low" }. This would allow for more metadata to be supplied, like the script loading strategy. Related: <https://core.trac.wordpress.org/ticket/56408> and <https://core.trac.wordpress.org/ticket/54018>. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, exactly what I meant above 😅 |
||
} | ||
|
||
$result = wp_register_script( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe that property in
block.json
should become an object instead of a string. In the future we might need other properties in there too.cc @gziolo
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.
Absolutely! See below 😄 #8815 (comment)
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 think this would make sense as a future enhancement, that this doesn't need to be implemented in this PR. If the low fetch priority is wrong, it could be fixed with a call to the new
WP_Scripts_Modules::set_fetchpriority()
.