Skip to content

Instantly share code, notes, and snippets.

@mslinnea
Last active September 20, 2024 10:06
Show Gist options
  • Save mslinnea/4d0084b76896b21360e149e383d9ac09 to your computer and use it in GitHub Desktop.
Save mslinnea/4d0084b76896b21360e149e383d9ac09 to your computer and use it in GitHub Desktop.
WordPress Gutenberg Performance - Disable Block Editor Preload Paths
<?php
namespace Gutenberg_Performance;
/**
* Removes the Synced Patterns (reusable blocks) from the preload paths.
* Performance improvement for sites with large number of these blocks.
*
* @param array $paths Paths.
*
* @return array
*/
function block_editor_rest_api_preload_paths( $paths ) {
return array_values(
array_filter(
$paths,
function ( $v ) {
return ! is_string( $v ) || ! str_starts_with( $v, '/wp/v2/blocks?context=edit' );
},
)
);
}
add_filter( 'block_editor_rest_api_preload_paths', __NAMESPACE__ . '\block_editor_rest_api_preload_paths', 999, 1 );
@mslinnea
Copy link
Author

mslinnea commented Jun 5, 2024

@mslinnea
Copy link
Author

mslinnea commented Sep 5, 2024

This issue is being addressed in WordPress 6.7, see Gutenberg PR #58239, #64459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment