From fe6e43b438710ecd3b0a97bfbe74bc6559a3db69 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 19 Oct 2023 01:45:37 -0600 Subject: [PATCH] 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 --- plugins/woocommerce/changelog/add-script-strategy | 4 ++++ plugins/woocommerce/includes/class-wc-frontend-scripts.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/add-script-strategy diff --git a/plugins/woocommerce/changelog/add-script-strategy b/plugins/woocommerce/changelog/add-script-strategy new file mode 100644 index 00000000000..7ee37500dc3 --- /dev/null +++ b/plugins/woocommerce/changelog/add-script-strategy @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Use the Script API strategy feature to defer front-end scripts in WordPress 6.3+ \ No newline at end of file diff --git a/plugins/woocommerce/includes/class-wc-frontend-scripts.php b/plugins/woocommerce/includes/class-wc-frontend-scripts.php index 5eb6d1e5b3a..dff3ad22ee6 100644 --- a/plugins/woocommerce/includes/class-wc-frontend-scripts.php +++ b/plugins/woocommerce/includes/class-wc-frontend-scripts.php @@ -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 instead of in the . 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 instead of in the . 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 ); }