Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created August 27, 2016 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhrrgn/9ded4bb9edcc6e2293f9ebdcd318dbef to your computer and use it in GitHub Desktop.
Save dhrrgn/9ded4bb9edcc6e2293f9ebdcd318dbef to your computer and use it in GitHub Desktop.
var imageUrls = [/* image urls here */];
// The basic prefetch and forget.
imageUrls.map((url) => Image.prefetch(url));
// ------------- OR -------------
// Prefetch and replace image urls that fail to load with a default image URL
// Note: You could/should bundle the default image with the app so it doesn't
// need prefetched, and would load instantly.
// Prefetch a default image (just one I found on google, i don't own the image)
const defaultImageUrl = 'http://xpenology.org/wp-content/themes/qaengine/img/default-thumbnail.jpg';
Image.prefetch(defaultImageUrl);
imageUrls.map((url, index) => {
// If you used a bundled image instead, you could just set the URL to `null`
// and check for that when rendering it, and display the default one instead.
Image.prefetch(url).catch(e => imageUrls[index] = defaultImageUrl);
});
@progsmile
Copy link

How about?)
imageUrls.map(Image.prefetch);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment