Quick follow-up here.
In delving more into optimization for the other JavaScript code on my site, I learned that either tag will load the JS file asynchronously – but using async
will interrupt the parsing to run the loaded JavaScript, whereas using defer
will not.
With defer
, the script will load in the background and then run when the DOM is fully built. So defer
is definitely for better to use whenever possible.
The problem is that you cannot defer a script that has already been async’ed (like with Koko). If you try to specify both (like having an optimization plugin add defer
), then the browser will always give async
higher priority, thus negating the defer
.
So all this is to say that for best optimization and page loading speed, it sounds like if the Koko plugin removed async
and used defer
instead, it would be a better outcome. ??
https://flaviocopes.com/javascript-async-defer/
https://javascript.info/script-async-defer
https://stackoverflow.com/questions/10808109/script-tag-async-defer
https://stackoverflow.com/questions/13821151/can-you-use-both-the-async-and-defer-attributes-on-a-html-script-tag
And the defer
attribute enjoys very broad browser support:
https://caniuse.com/script-defer
Cheers.
-
This reply was modified 3 years, 6 months ago by roam92.
-
This reply was modified 3 years, 6 months ago by roam92.