Alex Styl
05/22/2025, 8:53 PM@Composable
fun Script(
src: String,
onLoad: () -> Unit = { debugln { "✅ $src loaded" } },
type: String = "text/javascript",
) {
LaunchedEffect(Unit) {
val script = document.createElement("script") as HTMLScriptElement
script.src = src
script.type = type
script.onload = { onLoad() }
document.head?.appendChild(script)
}
}
Can be used like this
Script(
src = "scripts/zip-full.min.js",
type = "module",
)
and the script is in the resources
folderAlex Styl
05/22/2025, 9:31 PMephemient
05/22/2025, 11:12 PM<script src="scripts/zip-full.min.js" async>
directly in your HTML?Alex Styl
05/23/2025, 10:05 AM