Skip to content

Navigation: Preload API requests #24642

@noisysocks

Description

@noisysocks

When loading the Navigation screen, there are a lot of loading spinners due to API requests to /menus and /menu-items. We should preload these requests so that the screen appears faster.

For reference, here's how edit-site does this:

// Preload block editor paths.
// most of these are copied from edit-forms-blocks.php.
$preload_paths = array(
'/?context=edit',
'/wp/v2/types?context=edit',
'/wp/v2/taxonomies?context=edit',
'/wp/v2/pages?context=edit',
'/wp/v2/themes?status=active',
array( '/wp/v2/media', 'OPTIONS' ),
);
$preload_data = array_reduce(
$preload_paths,
'rest_preload_api_request',
array()
);
wp_add_inline_script(
'wp-api-fetch',
sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ),
'after'
);

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions