Load/execute JavaScript asynchronously
function loadJs(url){ | |
return new Promise( (resolve, reject) => { | |
if (document.querySelector(`head > script[src="${src}"]`) !== null) return resolve() | |
const script = document.createElement("script") | |
script.src = url | |
script.onload = resolve | |
script.onerror = reject | |
document.head.appendChild(script) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Usage: