Skip to content

Instantly share code, notes, and snippets.

@james2doyle
james2doyle / get-script-promise.js
Created November 17, 2016 18:37
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);