varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.41k stars 64 forks source link

Allow adding <body> scripts in a kobweb block in the build script #299

Open bitspittle opened 11 months ago

bitspittle commented 11 months ago

"There are some scripts, such as bootstrap popper, that need to be added to the body, not the head. Where would this be added?"

Right now, in your project's build script, you can do

kobweb { app { head { ... } } }

and this defines scripts that go in the head block.

It could be nice to also support

kobweb { app { body { ... } } }

The generated code would look something like this:

<!DOCTYPE html>
<html>
<head>
  <!-- kobweb head items go here -->
</head>
<body>
  <div id="root"></div>
  <script src="/site.js"></script>
  <!-- kobweb body items go here -->
</body>
</html>
bitspittle commented 11 months ago

Note that you can workaround this missing feature for now by running some logic in a LaunchedEffect(Unit) block in your MyApp function:

val script = document.createElement("script")
script.asDynamic().src = "https://gist.github.com/stevdza-san/35c3f45ca39bd1ee62ece3e324dc4184.js"
document.body!!.appendChild(script)