Sitemap
Switch your coding life

Switch your coding life

[Remote available] I am a software engineer with 15 years of experience. Currently, I am working at Glovo, one of the biggest food delivery companies in Europe.

Coil — Place holder and error image

1 min readFeb 6, 2026
Press enter or click to view image in full size
Coil place holders

Curiosly there are two ways to add placeholder and error image on coil. You can specify it either on the model or on the Asynch Image itself:

AsyncImage(
model = ImageRequest
.Builder(LocalContext.current)
.data(imageUrl)
.crossfade(true)
.build(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1400f/800f),
placeholder = painterResource(R.drawable.coillogo),
error = painterResource(R.drawable.coillogo)
)
AsyncImage(
model = ImageRequest
.Builder(LocalContext.current)
.data(imageUrl)
.crossfade(true)
.placeholder(R.drawable.coillogo)
.error(R.drawable.coillogo)
.build(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1400f/800f),
)

Of course, if you set the model as url, this will also work

AsyncImage(
model = imageUrl,
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1400f/800f),
placeholder = painterResource(R.drawable.coillogo),
error = painterResource(R.drawable.coillogo)
)

Now, based on my actual experience on prod, if you are using ImageRequest , it is better to set the place holder and the error image on the ImageRequest itself. Otherwise there might be bitmap duplicated in the App heap (I saw it once, not consistent thou)

Get Switch your coding life’s stories in your inbox

Join Medium for free to get updates from this writer.

Source code: https://github.com/jiahaoliuliu/CoilImageCaching/tree/placeHoldersAndErrorImages

--

--

Switch your coding life
Switch your coding life

Written by Switch your coding life

[Remote available] I am a software engineer with 15 years of experience. Currently, I am working at Glovo, one of the biggest food delivery companies in Europe.