Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created January 14, 2012 04:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/1610358 to your computer and use it in GitHub Desktop.
Save jrmoran/1610358 to your computer and use it in GitHub Desktop.
dynamic script loader
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