Created
June 6, 2017 18:38
-
-
Save markmur/7357673e9467f5fe92972f508a253e1a to your computer and use it in GitHub Desktop.
Preload Images with Promises
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
| const preloadImages = (images) => Promise.all(images.map(image => | |
| new Promise(resolve => { | |
| const img = new Image(); | |
| img.onload = () => (resolve(image)); | |
| img.onerror = () => (resolve(image)); | |
| img.src = image; | |
| }) | |
| )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment