From 4c19578cdfe652550929c5575f497ae687213484 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:34:24 +0200 Subject: [PATCH] Gutenberg: Dequeue editor assets when they aren't in use (#34268) * Gutenberg: Dequeue editor assets when they aren't in use * Add changelog * Fix whitespace --- .../changelog/update-dequeue-editor-assets-perf | 4 ++++ projects/plugins/jetpack/class.jetpack-gutenberg.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/update-dequeue-editor-assets-perf diff --git a/projects/plugins/jetpack/changelog/update-dequeue-editor-assets-perf b/projects/plugins/jetpack/changelog/update-dequeue-editor-assets-perf new file mode 100644 index 0000000000000..e7b9ea82925a1 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-dequeue-editor-assets-perf @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Gutenberg: Dequeue editor assets when they aren't in use \ No newline at end of file diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index c671e44d3ebfb..9482e9636301c 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -622,6 +622,18 @@ public static function enqueue_block_editor_assets() { return; } + /** + * This can be called multiple times per page load in the admin, during the `enqueue_block_assets` action. + * These assets are necessary for the admin for editing but are not necessary for each pattern preview. + * Therefore we dequeue them, so they don't load for each pattern preview iframe. + */ + if ( ! wp_should_load_block_editor_scripts_and_styles() ) { + wp_dequeue_script( 'jp-tracks' ); + wp_dequeue_script( 'jetpack-blocks-editor' ); + + return; + } + $status = new Status(); // Required for Analytics. See _inc/lib/admin-pages/class.jetpack-admin-page.php.