-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from all commits
dbcd32c
5207c27
088366d
9eab85d
d9c4037
4f82a4f
f2cd9be
ff4fd36
9edbe4c
021fe74
34ef7fa
e54274a
cc1d909
4197eb2
74a49e1
75fb879
0e9994a
06e9cac
f91c61d
4596644
2172e9e
535669d
fe366e2
f704f5e
38150dc
f05ca72
607ce0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -158,6 +158,7 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 2.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 4.3.0 A return value was added. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param string $handle Name of the script. Should be unique. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param string|false $src Full URL of the script, or path of the script relative to the WordPress root directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -171,8 +172,9 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Optional. An array of additional script loading strategies. Default empty array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return bool Whether the script has been registered. True on success, false on failure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -193,6 +195,9 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( ! empty( $args['strategy'] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$wp_scripts->add_data( $handle, 'strategy', $args['strategy'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( ! empty( $args['fetchpriority'] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$wp_scripts->add_data( $handle, 'fetchpriority', $args['fetchpriority'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. The fetchpriority is checked against an allowlist for modules. I don't see that for scripts. Did I overlook that or should it be included? 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. @sirreal In the case of classic scripts, the
There isn't any allowlist to default to 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. More than default I'm wondering about accepting arbitrary values. It's not likely harmful, but perhaps I understand it's a well defined set of values: For example: wp_enqueue_script( 'example', '/ex.js', array(), '…' );
wp_scripts()->add_data( 'example', 'fetchpriority', 'silly' ); produces <script src="/ex.js?ver=…" id="example-js" fetchpriority="silly"></script> which is… silly 🙂 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. That's a good point. For wordpress-develop/src/wp-includes/class-wp-scripts.php Lines 811 to 837 in 75fb879
This would make sense to include there as well for |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $registered; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -339,6 +344,7 @@ function wp_deregister_script( $handle ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 2.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 6.9.0 The $fetchpriority parameter of type string was added to the $args parameter of type array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param string $handle Name of the script. Should be unique. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -352,8 +358,9 @@ function wp_deregister_script( $handle ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Optional. An array of additional script loading strategies. Default empty array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $strategy Optional. If provided, may be either 'defer' or 'async'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @type string $fetchpriority Optional. The fetch priority for the script. Default 'auto'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $args = array() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -378,6 +385,9 @@ function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( ! empty( $args['strategy'] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$wp_scripts->add_data( $_handle[0], 'strategy', $args['strategy'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( ! empty( $args['fetchpriority'] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$wp_scripts->add_data( $_handle[0], 'fetchpriority', $args['fetchpriority'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$wp_scripts->enqueue( $handle ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.