Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jlcampana/7638706 to your computer and use it in GitHub Desktop.
Save jlcampana/7638706 to your computer and use it in GitHub Desktop.
Cargar fichero JS después de que haya cargado otro
/**
*
* Chainable external javascript file loading
* http://www.webtoolkit.info/
*
**/
scriptLoader.load([
'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'
'your-script.js'
]);
var scriptLoader = {
_loadScript: function (url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
if (callback) {
script.onreadystatechange = function () {
if (this.readyState == 'loaded') callback();
}
script.onload = callback;
}
head.appendChild(script);
},
load: function (items, iteration) {
if (!iteration) iteration = 0;
if (items[iteration]) {
scriptLoader._loadScript(
items[iteration],
function () {
scriptLoader.load(items, iteration+1);
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment