Skip to content

Instantly share code, notes, and snippets.

@markmur
Created June 6, 2017 18:38
Show Gist options
  • Select an option

  • Save markmur/7357673e9467f5fe92972f508a253e1a to your computer and use it in GitHub Desktop.

Select an option

Save markmur/7357673e9467f5fe92972f508a253e1a to your computer and use it in GitHub Desktop.
Preload Images with Promises
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