Last active
November 28, 2024 08:17
-
-
Save frontenddeveloping/5a9bb6082c24480c0f1c to your computer and use it in GitHub Desktop.
Async javascript loading (with saving order).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The main feature is script.async = false. | |
The async IDL attribute controls whether the element will execute asynchronously or not. | |
So if you will set async to false, scripts will load without blocking user i/o, but scripts will execute synchronously. | |
Support: | |
FF 4+ | |
FF for Android All Versions | |
IE 10+ (starting with preview 2) | |
Chrome 12+ | |
Chrome For Android All versions | |
Safari 5.1+ | |
iOS Safari 5.1+ | |
Android Browser 3.0+ (honeycomb on up) | |
Opera 15.0+ | |
Opera Mobile 16.0+ | |
*/ | |
[ | |
'1.js', | |
'2.js' | |
].forEach(function(src) { | |
var script = document.createElement('script'); | |
script.src = src; | |
script.async = false; | |
document.head.appendChild(script); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment