Last active
August 23, 2017 05:00
-
-
Save sampotts/6ed29257af53dab18d45a75f3a632087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Async load a script with a callback | |
(function () { | |
function async(u, c, a) { | |
var d = document; | |
var t = 'script'; | |
var o = d.createElement(t); | |
var s = d.getElementsByTagName(t)[0]; | |
o.src = u; | |
if (typeof a === 'object') { | |
for (var attr in a) { | |
s.setAttribute(attr, a[attr]); | |
} | |
} | |
if (c) { | |
o.addEventListener('load', function (e) { | |
c(null, e); | |
}, false); | |
} | |
s.parentNode.insertBefore(o, s); | |
} | |
async('https://path.to/your/script.js', function () { | |
// This will get called on load | |
}, { | |
// Any attributes that need adding to the script tag as key/value pairs | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment