Skip to content

Instantly share code, notes, and snippets.

@moroya
Created December 11, 2012 15:32
Show Gist options
  • Select an option

  • Save moroya/4259382 to your computer and use it in GitHub Desktop.

Select an option

Save moroya/4259382 to your computer and use it in GitHub Desktop.
(function(){
var loadCount = 0;
var scriptURL = [
'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js',
'//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js'
];
function getScript(src, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if(this.readyState == 'complete') {
callback.apply();
}
}
script.onload = callback; // IE対策
script.src = src;
head.appendChild(script);
}
function loadScripts() {
getScript(scriptURL[loadCount], function(){
loadCount++;
console.log('loaded');
if(loadCount < scriptURL.length) {
loadScripts();
}
});
}
window.onload = loadScripts;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment