3

I load my images into an android app with the Coil library. And it instantly shows me cached images if there is no internet. But when there is an internet connection, the Coil loads images again, and for a while I see the placeholder. I think it's a very strange logic. How can I make it show me the cached images instantly even if there is an internet connection?

My current code:

fun ImageView.setPhoto(photoLink: String) {
    load(photoLink) {
        crossfade(true)
        placeholder(R.drawable.placeholder)
        error(R.drawable.placeholder)
        size(ViewSizeResolver(this@setPhoto))
    }
}
MaxAstin
  • 463
  • 5
  • 14

1 Answers1

9

Try disabling the cache headers support.

val imageLoader = ImageLoader.Builder(context)
        .respectCacheHeaders(false)
        .build()
Coil.setImageLoader(imageLoader)
Serhii Petrenko
  • 320
  • 2
  • 12
  • Where does this go? – coderforlife Jan 24 '23 at 23:41
  • I did find out that you can do something similar with the ImageLoaderFactory on your Application instance: https://coil-kt.github.io/coil/getting_started/ – coderforlife Jan 24 '23 at 23:43
  • 1
    @coderforlife, it's not a big deal where to put that, because Coil is a singleton, and changes are applied across the app. I prefer to do that in MainActivity if the app is single activity or in Application class if not – Serhii Petrenko Apr 06 '23 at 10:57