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.