Does React Native cache remote images?
I have an app that downloads dozens of images remotely. These images seem to cache in my app, however, I'm not sure if it's the OS that's doing that by default, or if React Native is caching them.
If it's React Native, is there any way to customize how long they're cached? Or does the remote server define that?
react-native-fast-image is a performant React Native component for loading images. FastImage aggressively caches all loaded images. You can add your own request auth headers and preload images. react-native-fast-image even has GIF caching support.
In short: Any images that you import in your React components should be stored close to where they are used (preferably in the same directory). Any images that you do not import in your React components (e.g. favicons ) should be stored in your public/ directory, e.g. under a favicons/ folder.
React Native FastImage is a quick way to load images in React Native. All loaded pictures are aggressively cached by FastImage. You may add your own auth headers and preload pictures to your requests. GIF caching is also supported by react-native-fast-image.
Update:
Images are cached by the native Image module. Please have a look at this for more info.
It's not ReactNative directly, it's just fetch
that does the cache work. However, fetch
behavior also relies on server settings (cache
header most of the times). More on fetch API (with nice example on how to define cache
in Request headers) here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With