Created
October 27, 2022 23:15
-
-
Save AlphaT7/ac9e7a5edeec0ccd5cfc3973037e7b42 to your computer and use it in GitHub Desktop.
Fetch Multiple Resources
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
let resource1; | |
let resource2; | |
function fetchResources() { | |
// works with any type of resource; image/audio/video/json/font/txt etc; | |
let r1 = fetch("./assets/resource/resource1.json").then((response) => { | |
return response.json(); | |
}); | |
let r2 = fetch("./assets/resource/resource2.json").then((response) => { | |
return response.json(); | |
}); | |
Promise.all([r1, r2]) | |
.then((values) => { | |
[resource1, resource2] = [values[0].data, values[1].data]; | |
}) | |
.then(() => { | |
console.log("Resources Loaded."); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment