Blocks: Revisit pattern for enqueuing scripts and styles #2756
Labels
[Feature] Block API
API that allows to express the block paradigm.
[Type] Task
Issues or PRs that have been broken down into an individual action to take
Related: #2751
With the proposal in #2751 to require a PHP block definition for all blocks, it becomes reasonable to revisit whether scripts and styles should be enqueued separately from the block definition itself. Notably, this could have an impact on the front-end display of a block, as currently we must enqueue all scripts and styles for all blocks, regardless of whether a block of that particular type exists on the current screen. If the script and style handles were defined with the block, it is possible to limit this to only the blocks present in the current screen. This would, however, require that the post contents be parsed prior to display to detect blocks present in the post, to then check against all registered block types and associated script and styles handles. We should measure the performance impact of this parsing in relation to the benefit associated with filtering scripts.
Before:
After:
Alternatively, these files could be "discovered" adjacent the block registering file by naming conventions (e.g. find
style.css
,edit.css
,block.js
adjacentmyblock/index.php
). This could encourage developers to define their blocks in a standalone folder/file structure for easier separation overview.The text was updated successfully, but these errors were encountered: