You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The block.json convention is extremely convenient, however it does add a few extra steps when core blocks get instantiated:
We go through folders and look for block.json files
When we locate a file, we read its contents
json_decode the file contents
Register the block using the decoded data
All these things happen on each page load. We could improve the performance and save some processing for all sites by doing one of 2 things:
Cache the data for blocks
Add an extra task in our compilers, saving the decoded JSON data as a PHP array
Caching the data can be a little complicated because we'd still need to check the JSON file on each page-load to make sure there have been no changes to the file (maybe using a filemtime call - which would still be more effective than reading the file contents & decoding it). Caching would also require a DB call - which would still be better than the current processes that run, but not as optimal as the alternative below.
Adding an extra task and compile the decoded JSON data as a PHP array seems like a better choice. It would be a lot easier to parse a native PHP array on each page-load, and we can also take care of development tasks etc.
We already use the json2php package in Gutenberg, so adding a new task for this should not be a difficult task.
The text was updated successfully, but these errors were encountered:
It sounds like a similar improvement to what we did in WordPress core for the script asset files. We changed the output format from JSON to PHP and included a logic that combines them all into a single file:
I haven't done any more profound analysis, but it seems like changing the build process to convert block.json files into a single combined PHP file with everything bundled together might work great for WordPress core. We might also consider it for the Gutenberg plugin since we already do code transformations for PHP when present for core blocks.
The
block.json
convention is extremely convenient, however it does add a few extra steps when core blocks get instantiated:block.json
filesjson_decode
the file contentsAll these things happen on each page load. We could improve the performance and save some processing for all sites by doing one of 2 things:
Caching the data can be a little complicated because we'd still need to check the JSON file on each page-load to make sure there have been no changes to the file (maybe using a
filemtime
call - which would still be more effective than reading the file contents & decoding it). Caching would also require a DB call - which would still be better than the current processes that run, but not as optimal as the alternative below.Adding an extra task and compile the decoded JSON data as a PHP array seems like a better choice. It would be a lot easier to parse a native PHP array on each page-load, and we can also take care of development tasks etc.
We already use the
json2php
package in Gutenberg, so adding a new task for this should not be a difficult task.The text was updated successfully, but these errors were encountered: