kobweb icon indicating copy to clipboard operation
kobweb copied to clipboard

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

Open bitspittle opened this issue 2 years ago • 1 comments

"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 avatar Aug 19 '23 00:08 bitspittle

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)

bitspittle avatar Aug 19 '23 00:08 bitspittle