Last active
November 22, 2023 10:27
-
-
Save ZacharyCouchman/d5df5f6e73a803471386f853de7960c2 to your computer and use it in GitHub Desktop.
This file contains 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
// dynamically load a script and wait for load event | |
async function loadScript(url) { | |
return new Promise((resolve, reject) => { | |
let ourScript = document.createElement('script'); | |
ourScript.addEventListener('load', () => { | |
console.log('script was loaded'); | |
resolve('awesome'); | |
}); | |
ourScript.addEventListener('error', () => { | |
console.log('something went wrong loading ourScript'); | |
reject('sad'); | |
}); | |
// add your script's src here | |
ourScript.src = url; | |
document.head.appendChild(ourScript); | |
}); | |
} | |
loadScript('https://cdn.jsdelivr.net/npm/...') | |
.then((result) => console.log(result)) | |
.catch((error) => console.error(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment