Last active
August 29, 2015 14:22
-
-
Save doublejosh/19b38cd3285d0a70729b to your computer and use it in GitHub Desktop.
Sequentially load files
This file contains hidden or 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 loadedPromise, | |
| paths = [ | |
| '//code.jquery.com/jquery-1.11.3.min.js', | |
| '//cdnjs.cloudflare.com/ajax/libs/jStorage/0.4.12/jstorage.min.js' | |
| ]; | |
| function simpleInclude(path) { | |
| return new Promise(function (resolve, reject) { | |
| var script = document.createElement('script'); | |
| script.src = path; | |
| document.head.appendChild(script); | |
| script.onload = function() { | |
| resolve(); | |
| }; | |
| }); | |
| } | |
| // Sequential loading. | |
| loadedPromise = paths.reduce(function (previous, current) { | |
| return previous.then(function () { | |
| return simpleInclude(current); | |
| }); | |
| // Initial promise to kick off the chain. | |
| }, Promise.resolve(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@doublejosh noticed you have
previousandcurrentvars declared outside the function they're used in. That's unnecessary. Can just remove lines 2 & 3.