Last active
September 11, 2020 12:41
-
-
Save munkacsitomi/0ccad3d0a148925c9565cf5d55de7265 to your computer and use it in GitHub Desktop.
Control the order of the script loads
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
var loadScript = (src, callback) => { | |
var script = document.createElement('script'); | |
script.src = src; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
script.onload = callback; | |
} | |
(function() { | |
loadScript('firstScript.js', function() { | |
console.log('First script loaded!'); | |
loadScript('secondScript.js', function() { | |
console.log('Second script loaded!'); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment