Created
January 14, 2012 04:55
-
-
Save jrmoran/1610358 to your computer and use it in GitHub Desktop.
dynamic script loader
This file contains 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
var myLoader = function(filename, fun) { | |
var head = document.getElementsByTagName('head')[0], | |
script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = filename; | |
if(typeof fun === 'function'){ script.onload = fun; } | |
head.appendChild(script); | |
}; | |
// Usage | |
myLoader('a1.js', function(){ | |
myLoader('a2.js', function() { | |
console.log('Hello'); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment