From 69fe99333b77f622698b052b0a5c312079c8160d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 May 2025 18:39:06 -0700 Subject: [PATCH 1/5] Add fetchpriority=low support to script modules --- lib/client-assets.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 4a94ca212c3422..e2f75f119c81b7 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -653,8 +653,14 @@ function gutenberg_default_script_modules() { break; } + // All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering. + // Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource. + $args = array( + 'fetchpriority' => 'low', + ); + $path = gutenberg_url( "build-module/{$file_name}" ); - wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'] ); + wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'], $args ); // The 5th args parameter is proposed in . } } remove_action( 'wp_default_scripts', 'wp_default_script_modules' ); From e2828a77a944109364a8958255d263eec03b6bc6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 3 Sep 2025 15:21:13 -0700 Subject: [PATCH 2/5] Update comment now that change landed in core --- lib/client-assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 02f66568d01719..ec3fb147120a50 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -660,7 +660,7 @@ function gutenberg_default_script_modules() { ); $path = gutenberg_url( "build-module/{$file_name}" ); - wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'], $args ); // The 5th args parameter is proposed in . + wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'], $args ); // The $args parameter is new as of WP 6.9 per . } } remove_action( 'wp_default_scripts', 'wp_default_script_modules' ); From 6c381102fcdd5c474718a6a85bd3203c5edb0e04 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 3 Sep 2025 17:20:51 -0700 Subject: [PATCH 3/5] Add reference to related GB issue --- lib/client-assets.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/client-assets.php b/lib/client-assets.php index ec3fb147120a50..966fde356383f0 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -655,6 +655,7 @@ function gutenberg_default_script_modules() { // All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering. // Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource. + // For allowing a block to opt-in to another fetchpriority, see . $args = array( 'fetchpriority' => 'low', ); From 3cc250e513a8dc8ce9e759b06eefefece545c7b7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 3 Sep 2025 22:14:46 -0700 Subject: [PATCH 4/5] Use multi-line comment Co-authored-by: Mukesh Panchal --- lib/client-assets.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 966fde356383f0..decc3c21ec972c 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -653,9 +653,11 @@ function gutenberg_default_script_modules() { break; } - // All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering. - // Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource. - // For allowing a block to opt-in to another fetchpriority, see . + /* + * All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering. + * Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource. + * For allowing a block to opt-in to another fetchpriority, see . + */ $args = array( 'fetchpriority' => 'low', ); From 1ab3c3434e3e5bb338d11f8a7b9775cb8003beb0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 5 Sep 2025 19:37:19 -0700 Subject: [PATCH 5/5] Add comment explaining why a11y is fetchpriority=low Co-authored-by: Jon Surrell --- lib/client-assets.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/client-assets.php b/lib/client-assets.php index decc3c21ec972c..3d1db3ad03c752 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -657,6 +657,12 @@ function gutenberg_default_script_modules() { * All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering. * Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource. * For allowing a block to opt-in to another fetchpriority, see . + * + * Also, the @wordpress/a11y script module is intended to be used as a dynamic import dependency, in which case + * the fetchpriority is irrelevant. See . + * However, in case it is added as a static import dependency, the fetchpriority is explicitly set to be 'low' + * since the module should not be involved in the critical rendering path, and if it is, its fetchpriority will + * be bumped to match the fetchpriority of the dependent script. */ $args = array( 'fetchpriority' => 'low',