Created
August 21, 2022 19:57
-
-
Save zisra/13ed42837ab86db94377f364e3406ea6 to your computer and use it in GitHub Desktop.
Add scripts
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
const addScripts = urls => { | |
let scriptsLoaded = 0; | |
return new Promise((resolve, reject) => { | |
urls.forEach((url) => { | |
const script = document.createElement('script'); | |
script.src = url; | |
document.head.appendChild(script); // or document.body | |
script.onload = () => { | |
scriptsLoaded++; | |
if (scriptsLoaded === urls.length) { | |
resolve(); | |
} | |
}; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment