Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Created November 25, 2020 14:32
Show Gist options
  • Select an option

  • Save LiamChapman/814b3119cb07e5546019491cb272dfcb to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/814b3119cb07e5546019491cb272dfcb to your computer and use it in GitHub Desktop.
cache image function
export const cacheImages = async (srcArray) => {
const promises = await srcArray.map((src) => {
return new Promise((resolve, reject) => {
const img = new Image();
img.src = src;
img.onload = resolve();
img.onerror = reject();
});
});
await Promise.all(promises);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment