Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created October 26, 2012 22:48
Show Gist options
  • Save Sigmus/3962012 to your computer and use it in GitHub Desktop.
Save Sigmus/3962012 to your computer and use it in GitHub Desktop.
Run scripts sequentially using pipe()
var files = [
'first.js',
'second.js',
'third.js',
'fourth.js'
];
var scriptsLoaded;
while( files.length ) {
(function() {
var currentUrl = files.shift();
if (typeof scriptsLoaded === 'undefined') {
scriptsLoaded = $.getScript( currentUrl );
}
else {
scriptsLoaded.pipe(function() { return $.getScript( currentUrl ); })
}
}());
}
$.when( scriptsLoaded ).done(function() {
// All scripts are now loaded assuming none of them failed
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment