Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register interactivity scripts using new 'defer' strategy support #51930

Closed
joemcgill opened this issue Jun 26, 2023 · 0 comments · Fixed by #52536
Closed

Register interactivity scripts using new 'defer' strategy support #51930

joemcgill opened this issue Jun 26, 2023 · 0 comments · Fixed by #52536
Assignees
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.

Comments

@joemcgill
Copy link
Member

joemcgill commented Jun 26, 2023

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.

@joemcgill joemcgill added [Type] Enhancement A suggestion for improvement. [Feature] Interactivity API API to add frontend interactivity to blocks. labels Jun 26, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants