-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
What problem does this address?
Currently, the interactivity API uses a filter on the script_loader_tag
hook (code reference) to dynamically add a defer
attribute to the script tags when they are printed to the screen.
Now that official support for registering scripts with an async
or defer
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 for wp_register_script
and wp_enqueue_script
so that an array can be passed to the sixth param with the shape of:
array(
'in_footer' => false,
'strategy' => 'defer'
);
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 the defer
attribute.