title: How to preload Coil image in Compose?
body: <p>I have a pager (Accompanist) with image that are get from web with Coil in Compose.</p>
  <p>The <code>rememberPainter()</code> seem to only call the request when the <code>Image</code> composable is shown for the first time.</p>
  <p>So when I slide page in the pager, the <code>Image</code> show only at that moment and so we have to wait a moment.</p>
  <p>Any way to force the <code>rememberPainter</code> (Coil) to preload ?</p>
  <hr />
  <p>Edit 1 :</p>
  <p>Here is a simple version of my implementation (with lots of stuff around removed but that had no impact on the result) :</p>
  <pre class="lang-kotlin prettyprint-override"><code>@Composable
  private fun Foo(imageList: List&lt;ImageHolder&gt;) {
      if (imageList.isEmpty())
          return
  
      val painterList = imageList.map {
          rememberImagePainter(
              data = it.getDataForPainter(),
              builder = {
                  crossfade(true)
              })
      }
  
      ImageLayout(imageList, painterList)
  }
  
  @Composable
  fun ImageLayout(imageList: List&lt;ImageHolder&gt;, painterList: List&lt;Painter&gt;) {
      HorizontalPager(
          count = imageList.size,
          modifier = Modifier.fillMaxWidth(),
      ) { page -&gt;
          Image(
              painter = painterList[page],
              &quot;&quot;,
              modifier = Modifier
                  .fillMaxWidth()
                  .height(200.dp)
                  .background(
                      imageList[page].colorAverage
                  ),
              contentScale = ContentScale.Crop
          )
      }
  }
  </code></pre>
  <p>I tried with having directly the rememberImagePainter at the Image too just in case.
  But the problem is clearly that Image() of page 2, 3, 4 isn't rendered so Image don't do the call to the painter. I tried to look how it work inside but couldn't find.</p>
  <hr />
  <p>Edit 2 : I found a workaround but it's not clean</p>
  <pre class="lang-kotlin prettyprint-override"><code>for (painter in painterList) 
      Image(painter = painter, contentDescription = &quot;&quot;, modifier = Modifier.size(0.001.dp))
  </code></pre>
  <p>It force coil to load image and with a size really small like <code>0.001.dp</code> (with <code>0</code> it don't load).
  Also the problem is that in the builder you need to force a size or it will just load one pixel, so I force the full size of image as I don't know what size would have been available for the image.</p>