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 ); }