long.js runs first because of async=false Let script = document.createElement('script') Whatever loads first (probably small.js) – runs first: Here’s an example similar to what we’ve seen with defer: two scripts long.js and small.js, but now with async instead of defer. A fully independent script that runs when loaded. The DOM and other scripts don’t wait for them, and they don’t wait for anything. In other words, async scripts load in the background and run when ready. …or after an async script (if an async script is short or was in HTTP-cache).DOMContentLoaded may happen both before an async script (if an async script finishes loading after the page is complete).DOMContentLoaded and async scripts don’t wait for each other:.Other scripts don’t wait for async scripts, and async scripts don’t wait for them.The browser doesn’t block on async scripts (like defer).The async attribute means that a script is completely independent: But it has important differences in the behavior. The async attribute is somewhat like defer. The defer attribute is ignored if the tag has no src.
0 Comments
Leave a Reply. |