Created
October 26, 2012 22:48
-
-
Save Sigmus/3962012 to your computer and use it in GitHub Desktop.
Run scripts sequentially using pipe()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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