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
Is your feature request related to a problem? Please describe.
Currently when a block is included to be displayed on the front end of the site (not wp-admin). The preferred way to include the assets (js and css) for that block seems to be via the enqueue_block_assets action or by registering the scripts and style attributes in as attributes of the block in the register_block_type() function.
The problem is if a particular block requires a lot of JS code for example currently the JS could gets included on every page load if that block is present or not.
Describe the solution you'd like
It would be great if we could pass an attribute when registering the block that we only want to load the script and styles when the block is being displayed.
But I think a solution to this issue that is supported in Gutenberg would be best.
I would be more then happy to code something up but wanted to ask first if this is something we would consider.
I think this is related to #2756 and #5445, likely a duplicate in the latter case. Let's consolidate discussion there.
I anticipate a solution could leverage the script field of a registered block type added in #4039, so using it now could allow it to be enhanced automatically (i.e. future compatible).
Is your feature request related to a problem? Please describe.
Currently when a block is included to be displayed on the front end of the site (not wp-admin). The preferred way to include the assets (js and css) for that block seems to be via the
enqueue_block_assets
action or by registering the scripts and style attributes in as attributes of the block in theregister_block_type()
function.The problem is if a particular block requires a lot of JS code for example currently the JS could gets included on every page load if that block is present or not.
Describe the solution you'd like
It would be great if we could pass an attribute when registering the block that we only want to load the script and styles when the block is being displayed.
Currently I am implementing something that use the
render_callback
attribute and adds the loading of the assets in there. See https://github.com/Automattic/jetpack/pull/10405/filesBut I think a solution to this issue that is supported in Gutenberg would be best.
I would be more then happy to code something up but wanted to ask first if this is something we would consider.
cc: @aduth
The text was updated successfully, but these errors were encountered: