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

Unable to defer scripts using Wordpress 6.3+ #62

Open
harlessmark opened this issue Apr 30, 2024 · 0 comments
Open

Unable to defer scripts using Wordpress 6.3+ #62

harlessmark opened this issue Apr 30, 2024 · 0 comments
Assignees
Labels
bug Something isn't working php Requires understanding PHP

Comments

@harlessmark
Copy link

harlessmark commented Apr 30, 2024

Description of the bug

With Wordpress version >= 6.3.0, using am_modify_load_method results in the expected attribute not being added.

In this if statement, since I am always going to be using Wordpress version 6.3+, the defer string will never be added to $load_methods_to_async, so in turn will never be added to async_scripts, so in turn will never add the attribute to the tag.

Steps To Reproduce

On Wordpress 6.3 or greater, attempt to modify the load method for a script as documented.

// Defer an enqueued JavaScript asset.
am_modify_load_method(
  [
    'handle'      => 'footer-script', 
    'load_method' => 'defer',
  ]
);

Expected: The defer attribute is present on the script tag in the DOM
Actual: The defer attribute is missing from the script tag

Additional Information

We tried using the async-defer load method as a workaround, but that prints an enqueue error stating "there is no guarantee it will be available for its dependent asset.”

Acceptance Criteria

  • Set the minimum required version of WordPress to 6.3.
  • Use the new script loading features available in 6.3 without condition checks.
  • Ensure there is a unit test that covers this use case and that it passes.
  • Release this update alongside Remove the 'async-defer' load method #63 in a new v2.0.0 as a breaking change.
@harlessmark harlessmark added the bug Something isn't working label Apr 30, 2024
@kevinfodness kevinfodness added the php Requires understanding PHP label Aug 21, 2024
@mslinnea mslinnea self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working php Requires understanding PHP
Projects
None yet
Development

No branches or pull requests

3 participants