Skip to content

Instantly share code, notes, and snippets.

@archerU
archerU / get-script-promise.js
Created July 26, 2022 07:54 — forked from james2doyle/get-script-promise.js
Async load a script in the page and run it. Uses promises
// this function will work cross-browser for loading scripts asynchronously
function loadScript(src) {
return new Promise(function(resolve, reject) {
const s = document.createElement('script');
let r = false;
s.type = 'text/javascript';
s.src = src;
s.async = true;
s.onerror = function(err) {
reject(err, s);