Repository: JetBrains/compose-multiplatform
File: components/resources/library/src/webMain/kotlin/org/jetbrains/compose/resources/Resource.web.kt (Kotlin)

Code before:
@ExperimentalResourceApi
@Composable
fun preloadImageResource(
    resource: DrawableResource,
): State<ImageBitmap?> {
    val resState = remember(resource) { mutableStateOf<ImageBitmap?>(null) }.apply {
        value = imageResource(resource).takeIf { !it.isEmptyImageBitmapPlaceholder }
    }
    return resState
}


/**
 * Preloads a vector image resource and provides a [State] containing the loaded [ImageVector] or `null` if not yet loaded.
 *
 * Internally, it reads the resource bytes, converts them to a [ImageVector] object, and caches the result,
 * speeding up future accesses to the same resource when using @Composable [vectorResource] function.
 *
 * **Usage Example:**
 * ```
 * @Composable
 * fun MyApp() {
 *     val iconState by preloadVectorResource(Res.drawable.niceVectorIcon)
 *
 *     if (iconState != null) {
 *         Image(imageVector = vectorResource(Res.drawable.niceVectorIcon))
 *     }
 * }
 * ```
 *
 * @param resource The resource to be used.
 * @return A [State]<[ImageVector]?> object that holds the loaded [ImageVector] when available,
 * or `null` if the resource is not yet ready.
 */
@ExperimentalResourceApi
@Composable
fun preloadVectorResource(
    resource: DrawableResource,
): State<ImageVector?> {
    val resState = remember(resource) { mutableStateOf<ImageVector?>(null) }.apply {
        value = vectorResource(resource).takeIf { !it.isEmptyImageVectorPlaceholder }
    }
    return resState
}

Review comment (suggestion):
I'd prefer to show a high-level API: 
```kotlin
Image(
    painter = painterResource(Res.drawable.niceVectorIcon),
    contentDescription = ...
)
```

Code after:
 *         Box(modifier = Modifier.fillMaxSize()) {
 *             CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
 *         }
 *     }
 * }
 *
 * @Composable
 * fun MyImage() {
 *      // the image is taken from the cache thanks to preloadImageBitmap
 *      Image(painter = painterResource(Res.drawable.heavy_drawable), contentDescription = null)
 * }
 * ```
 *
 * @param resource The resource to be used.
 * @return A [State]<[ImageBitmap]?> object that holds the loaded [ImageBitmap] when available,
 * or `null` if the resource is not yet ready.
 */
@ExperimentalResourceApi
@Composable
fun preloadImageBitmap(
    resource: DrawableResource,
): State<ImageBitmap?> {
    val resState = remember(resource) { mutableStateOf<ImageBitmap?>(null) }.apply {
        value = imageResource(resource).takeIf { !it.isEmptyPlaceholder }
    }
    return resState
}


/**
 * Preloads a vector image resource and provides a [State] containing the loaded [ImageVector] or `null` if not yet loaded.
 *
 * Internally, it reads the resource bytes, converts them to a [ImageVector] object, and caches the result,
 * speeding up future accesses to the same resource when using @Composable [vectorResource] or [painterResource] functions.
 *
 * **Usage Example:**
 * ```
 * @Composable
 * fun MyApp() {
 *     val iconState by preloadImageVector(Res.drawable.heavy_vector_icon)
 *
 *     if (iconState != null) {
 *         MyIcon()
 *     } else {
 *         Box(modifier = Modifier.fillMaxSize()) {
 *              CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
 *          }
 *     }
 * }
 *
 * @Composable