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

'enqueueJs()' support to registering scripts with async and defer #313

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

ouun
Copy link
Contributor

@ouun ouun commented Nov 10, 2023

WordPress 6.3 introduced support for registering scripts with async and defer attributes. This PR updates enqueueJs() to support the new function signatures, with the prior $in_footer boolean parameter being overloaded to accept a new $args array parameter.

    bundle('app')->enqueueJs([
        'strategy' => 'defer',
        'in_footer' => true,
    ]);

This is backwards compatible by core:

For prior/existing usage of the wp_register_script() and wp_enqueue_script() functions making use of the $in_footer boolean param, backward compatibility is retained via logic that explicitly sets the scripts group to the applicable value for footer or header printing based on the boolean value passed to the new/overloaded $args parameter.

…`defer` attributes

WordPress 6.3 introduced support for registering scripts with async and defer attributes. This updates `enqueueJs()` to support the new function signatures, with the prior `$in_footer` boolean parameter being overloaded to accept a new `$args` array parameter. This is backwards compatible by core.
@Log1x
Copy link
Member

Log1x commented Nov 16, 2023

Can we update this so it defaults to a bool (specifically, true) so it doesn't break compatibility on earlier versions of WordPress?

@Log1x Log1x self-assigned this Nov 16, 2023
@ouun
Copy link
Contributor Author

ouun commented Nov 16, 2023

@Log1x you are right. Will change it to back to trueas default value.

@Log1x Log1x merged commit bb2fa70 into roots:main Nov 16, 2023
2 checks passed
@ouun ouun deleted the patch-2 branch November 16, 2023 22:33
QWp6t pushed a commit that referenced this pull request Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants