jayesbe / react-native-cacheable-image

An Image Component for React Native that will cache itself to disk.
MIT License
304 stars 78 forks source link

Image.prefetch any different? #38

Closed anshul-kai closed 7 years ago

anshul-kai commented 7 years ago

Just wondering if this lib offers anything over Image.prefetch? I realize that Image.prefetch is relatively new and this lib may have been introduced back in the day to overcome that limitation.

eneskaya commented 7 years ago

I just asked myself the same thing. Made an experiment, where I used prefetch to download a very large image from the exact same url. When running the app inside iOS Simulator and having the Debug navigator open, where you can see the 'Network' tab, I could see that it's loading the image every time, prefetch is called.

So, the function may cache the image for later usage. But it's not "intelligent" enough to decide wether the image exists in the cache or doesn't.

anshul-kai commented 7 years ago

Thanks for sharing your insight @eneskaya. How are you able to see network requests in debug mode?

jayesbe commented 7 years ago

I will look further into prefetch.

anshul-kai commented 7 years ago

Thanks @jayesbe. I wasn't able to verify @eneskaya's comment above as I'm still struggling logging my network requests. I do know that Image.prefetch doesn't fetch the image again within the same session of the app. It may not be persisting to disk if I had to make a guess.

A promise based prefetch in this library would be great to have.

eneskaya commented 7 years ago

The network requests can bee seen, when you run the app within iOS Simulator or on device in debug mode:

bildschirmfoto 2017-01-30 um 16 36 17

Then when I use Image.prefetch to fetch a very large image in a setInterval I can see, that every time a request is made.

eneskaya commented 7 years ago

Thats the result using Image.prefetch in a setInterval

bildschirmfoto 2017-01-30 um 16 41 51

anshul-kai commented 7 years ago

Thanks for sharing @eneskaya. I had forgotten about the Network info in XCode and was beating myself up with making it work in Chrome.

Your observation is inline with mine. Image.prefetch does fetch and cache the image for use in an Image component. Multiple renders of such an Image component use the same cached image but calling Image.prefetch again fetches the image from the remote.

eneskaya commented 7 years ago

You're welcome 😄 This issue can be closed then I think.

anshul-kai commented 7 years ago

Yes, I'll go ahead and close it. @jayesbe it'll be great to have the ability to prefetch a CacheableImage to avoid the ActivityIndicator.

jayesbe commented 7 years ago

@a-koka I agree a prefetch would be helpful. Will give it some thought.