Created
March 16, 2012 23:07
-
-
Save jhurliman/2053488 to your computer and use it in GitHub Desktop.
Asynchronous JavaScript Loader
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 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