Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Created October 5, 2016 06:28
Show Gist options
  • Save mohayonao/f6995fb138f02ccd6b4ebf13f46e54c6 to your computer and use it in GitHub Desktop.
Save mohayonao/f6995fb138f02ccd6b4ebf13f46e54c6 to your computer and use it in GitHub Desktop.
function importScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.async = 1;
script.type = "text/javascript";
script.src = src;
script.onerror = reject;
script.onload = () => {
document.body.removeChild(script);
resolve();
};
document.body.appendChild(script);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment