Created
August 2, 2017 17:09
-
-
Save tlareg/6150d515c280052e735069dbd6d92e4b to your computer and use it in GitHub Desktop.
load js script dynamically
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
function loadJS(src) { | |
let scriptEl = document.createElement('script') | |
scriptEl.type = 'application/javascript' | |
scriptEl.src = src | |
const scriptLoadedPromise = new Promise((resolve, reject) => { | |
scriptEl.onload = () => resolve() | |
}) | |
document.body.appendChild(scriptEl) | |
return scriptLoadedPromise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment