Created
July 13, 2021 09:10
-
-
Save maplemap/9a2b1b0f867ef6bda6ef40b72901787e to your computer and use it in GitHub Desktop.
Load script by Promise
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
const loadScriptByPromise = (url: string) => | |
new Promise(resolve => { | |
const head = document.getElementsByTagName('head')[0] | |
const script = document.createElement('script') | |
script.type = 'text/javascript' | |
script.addEventListener('load', function listener(){ | |
this.removeEventListener('load', listener) | |
resolve(script) | |
}) | |
script.src = url | |
head.appendChild(script) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment