Will Script Loaded With Async Attribute Delay Onload Event?
I have a page with a script tag in HEAD section: As it contains async attribute it loads asynchronou
Solution 1:
Yes, as you suggest, it will delay the window.onload
event.
Your first script, somescript.js
adds a child script
element to the page, before the page has finished loading (e.g. before window.onload
has fired), and the page now has to download and execute the src of that newly appended script
element before it can fire an onload
event.
If you didn't want it to delay the onload
event, you could make an AJAX
request to get the contents of otherscript.js
and simply eval
it so it executes in the global context (effectively the same as specifying it via a script
tag, but without delaying the onload
event).
Post a Comment for "Will Script Loaded With Async Attribute Delay Onload Event?"