I am exploring how to build a theme where most of the pages are loaded using the Rest API. I can load the index page and from there make GET requests to get posts json data and after build its content in the current page. Basically a SPA, at least to some extent.
The problem comes when trying to load a single post and its scripts/styles. As an example, Gutenberg permits loading a script or/and a style for each registered block using the enqueue_block_assets
hook.
I am trying to figure out a way to get the registered styles and scripts url for a specific post. My idea is to register a rest route or a field that returns the url of each script/style. I can then attach each script/style to the DOM, after the single post json data has been mounted.
global $wp_scripts;
returns the registered scripts and also the enqueued ones in the current page load. So I could not find a way to get that info specifying the post id from outside the single page load flow.
How can I get the list of enqueued/registered scripts and styles url for any specific post id?
or
Is there a better approach?
$GLOBALS['wp_styles']->do_items();
for styles. This should only list all styles, there are still loaded on the current page? That's should also work for the$wp_scripts
.