Register interactivity scripts using new 'defer' strategy support #51930
Labels
[Feature] Interactivity API
API to add frontend interactivity to blocks.
[Status] In Progress
Tracking issues with work in progress
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
Currently, the interactivity API uses a filter on the
script_loader_tag
hook (code reference) to dynamically add adefer
attribute to the script tags when they are printed to the screen.Now that official support for registering scripts with an
async
ordefer
strategy has landed in WP Core (trunk) in r56033, the interactivity API should be updated to make use of this feature.What is your proposed solution?
To do so, this will likely need
gutenberg_override_script
to be updated to support the updated function signature introduce forwp_register_script
andwp_enqueue_script
so that an array can be passed to the sixth param with the shape of:For backwards compatibility with older versions of WP, the strategy could be set directly on the script object after it is registered by manually calling
$wp_scripts->add_data( $handle, 'strategy', 'defer' )
and then applying the current filter approach if the final script tag does not contain thedefer
attribute.The text was updated successfully, but these errors were encountered: