From 52553b2cf7f414a6d355c2bf75f553709eaeeb40 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 27 Dec 2023 11:45:57 +0100 Subject: [PATCH 1/5] Move modules scripts to footer on classic themes --- lib/experimental/modules/class-gutenberg-modules.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index bbe51f1376a7db..04831053c83a3f 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -262,14 +262,15 @@ function gutenberg_dequeue_module( $module_identifier ) { Gutenberg_Modules::dequeue( $module_identifier ); } +$modules_position = wp_is_block_theme() ? 'wp_head' : 'wp_footer'; // Prints the import map in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_import_map' ) ); +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_import_map' ) ); // Prints the enqueued modules in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); // Prints the preloaded modules in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); From f13a53a6f908bc64d32dbf824b107107375819fc Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 27 Dec 2023 11:51:46 +0100 Subject: [PATCH 2/5] Move only required modules --- lib/experimental/modules/class-gutenberg-modules.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index 04831053c83a3f..8a48075170caa4 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -263,14 +263,14 @@ function gutenberg_dequeue_module( $module_identifier ) { } $modules_position = wp_is_block_theme() ? 'wp_head' : 'wp_footer'; -// Prints the import map in the head tag. +// Prints the import map in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_import_map' ) ); -// Prints the enqueued modules in the head tag. +// Prints the enqueued modules in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); -// Prints the preloaded modules in the head tag. -add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +// Prints the preloaded modules in the head tag in block themes. +add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); From 7c97c8ed5b9a25a6260319b801ff7974ccaa1052 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 27 Dec 2023 13:51:06 +0100 Subject: [PATCH 3/5] Move also the module preloads --- lib/experimental/modules/class-gutenberg-modules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index 8a48075170caa4..0a2da03545776e 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -269,8 +269,8 @@ function gutenberg_dequeue_module( $module_identifier ) { // Prints the enqueued modules in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); -// Prints the preloaded modules in the head tag in block themes. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +// Prints the preloaded modules in the head tag in block themes. Otherwise in the footer. +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); From 3edb69fc6f2ef4ea38b5ce4e4fa97425a0de2b1d Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 27 Dec 2023 14:25:52 +0100 Subject: [PATCH 4/5] Make preload only for block themes at head --- lib/experimental/modules/class-gutenberg-modules.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index 0a2da03545776e..73fbad253b233b 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -266,11 +266,13 @@ function gutenberg_dequeue_module( $module_identifier ) { // Prints the import map in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_import_map' ) ); -// Prints the enqueued modules in the head tag in block themes. Otherwise in the footer. +// Prints the enqueued modules in the head tag in block themes. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); -// Prints the preloaded modules in the head tag in block themes. Otherwise in the footer. -add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +// Prints the preloaded modules in the head tag in block themes. +if ( 'wp_head' === $modules_position ) { + add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +} // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); From f77a1e9499ada3b6cac434e8b248a0b274a0df64 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 27 Dec 2023 14:57:41 +0100 Subject: [PATCH 5/5] Revert "Make preload only for block themes at head" This reverts commit 3edb69fc6f2ef4ea38b5ce4e4fa97425a0de2b1d. --- lib/experimental/modules/class-gutenberg-modules.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index 73fbad253b233b..0a2da03545776e 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -266,13 +266,11 @@ function gutenberg_dequeue_module( $module_identifier ) { // Prints the import map in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_import_map' ) ); -// Prints the enqueued modules in the head tag in block themes. +// Prints the enqueued modules in the head tag in block themes. Otherwise in the footer. add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); -// Prints the preloaded modules in the head tag in block themes. -if ( 'wp_head' === $modules_position ) { - add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); -} +// Prints the preloaded modules in the head tag in block themes. Otherwise in the footer. +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 );