Skip to content

Instantly share code, notes, and snippets.

@mmeyers00
Created January 18, 2019 21:11
Show Gist options
  • Save mmeyers00/e9f9cdc1f5e378bc8c9f2b2a88858c97 to your computer and use it in GitHub Desktop.
Save mmeyers00/e9f9cdc1f5e378bc8c9f2b2a88858c97 to your computer and use it in GitHub Desktop.
Load external Javascript with a Promise
function loadjs(file) {
return new Promise(resolve => {
var script = document.createElement("script");
script.type = "application/javascript";
script.src = file;
document.body.appendChild(script);
resolve(true);
});
}
async function main() {
await loadjs('https://code.jquery.com/jquery-3.3.1.min.js');
console.log($(body).length);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment