Leverage Script API strategy feature to defer front end scripts in WP >=6.3 (#40686)
* Leverage strategy API to defer scripts from header rather than placing in footer * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
e302d4cac8
commit
fe6e43b438
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: update
|
||||
|
||||
Use the Script API strategy feature to defer front-end scripts in WordPress 6.3+
|
|
@ -120,7 +120,7 @@ class WC_Frontend_Scripts {
|
|||
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
||||
*/
|
||||
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
||||
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
|
||||
self::$scripts[] = $handle;
|
||||
wp_register_script( $handle, $path, $deps, $version, $in_footer );
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class WC_Frontend_Scripts {
|
|||
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
||||
*/
|
||||
private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
||||
private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
|
||||
if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
|
||||
self::register_script( $handle, $path, $deps, $version, $in_footer );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue