Skip to content

Instantly share code, notes, and snippets.

@unlight
Created October 17, 2011 08:30
Show Gist options
  • Save unlight/1292203 to your computer and use it in GitHub Desktop.
Save unlight/1292203 to your computer and use it in GitHub Desktop.
Include javascript file
function include(files) {
if (typeof(files) == 'string') files = [files];
var onload;
var script = document.createElement('script');
var file = files.shift();
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', file);
document.body.appendChild(script);
if (files.length > 0) {
onload = function() { include(files); }
script.onreadystatechange = onload;
script.onload = onload;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment