alleyinteractive / alleyinteractive/wp-asset-manager
Unable to defer scripts using Wordpress 6.3+
- Dominant language
- PHP
- Stars
- 30
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
### 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](https://github.com/alleyinteractive/wp-asset-manager/blob/production/php/class-asset-manager-scripts.php#L256-L260), 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](https://github.com/alleyinteractive/wp-asset-manager/blob/production/php/class-asset-manager-scripts.php#L265), so in turn will [never add the attribute](https://github.com/alleyinteractive/wp-asset-manager/blob/production/php/class-asset-manager-scripts.php#L120) to the tag.
### Steps To Reproduce
On Wordpress 6.3 or greater, attempt to modify the load method for a script as documented.
```php
// 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 #63 in a new v2.0.0 as a breaking change.
Contributor guide
Assessment
This issue has not been assessed yet.