Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does React Native cache remote images?

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?

like image 579
Dan Leveille Avatar asked Mar 04 '16 05:03

Dan Leveille


People also ask

Does React Native cache images?

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.

Where are images stored in React Native?

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.

How do I load images faster in React Native?

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.


1 Answers

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.

like image 188
Alberto Dallaporta Avatar answered Sep 21 '22 06:09

Alberto Dallaporta