Created
August 27, 2016 01:33
-
-
Save dhrrgn/9ded4bb9edcc6e2293f9ebdcd318dbef to your computer and use it in GitHub Desktop.
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
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about?)
imageUrls.map(Image.prefetch);