Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created March 16, 2012 23:07
Show Gist options
  • Save jhurliman/2053488 to your computer and use it in GitHub Desktop.
Save jhurliman/2053488 to your computer and use it in GitHub Desktop.
Asynchronous JavaScript Loader
// Async Loader v1.0.0
var include = function(scripts, done) {
if (typeof scripts === 'string') scripts = [scripts];
var loading = function() { scripts.pop() && !scripts.length && done && done.call(); };
scripts.forEach(function (script) {
var el = document.createElement('script');
el.addEventListener('load', loading), el.async = true, el.src = script;
document.head.appendChild(el);
});
return arguments.callee;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment