You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote this on the other project… but I’m not 100% sure about it. It’s a bit “magic” and I’m not sure we can just default to async without unexpectedly breaking things.
Async scripts can execute before the DOM is ready, so need to be sure to handle that case in your JS If necessary. Enabling this in an update could well break existing code.
I also am unsure about another case. What if a defer loaded script depends on an async one. Will it wait for that to be available before execution? I think so, but Im not totally sure.
I think we should add async and defer loading as an option in asset loader but i probably would default to nothing (or possibly defer…)
Async scripts can execute before the DOM is ready, so need to be sure to handle that case in your JS If necessary. Enabling this in an update could well break existing code.
I guess this wouldn’t really be a problem if you loaded your script in the footer, even if it’s async 🤔
We should have a way of registering that a script should be rendered with an
async
attribute, or included in apreload
list.In another project using this asset loader, a team recently wrote a custom wrapper which used this logic to set the "defaults" for scripts:
Then when registering the script the wrapper would add the relevant parameters:
Then, filter the script based on that data:
The note about
#12009
refers to this ticket to add async and defer handling to core wp_enqueue_script itself.The text was updated successfully, but these errors were encountered: