Kotlin web components
Write the HTML.
Keep the Kotlin right next to it.
A .lithe file is your markup, with the Kotlin that drives it and the CSS that styles it in the same place. Lithe renders it to HTML at build time and only ships JavaScript for the parts that move.
VS Code extension IntelliJ plugin
Still experimental, and on Maven Central since 0.1.0.
<script kotlin>
prop val step: Int = 1
var count by state(0)
val doubled by derived { count * 2 }
</script>
<div class="demo">
<button class="counter" type="button" @click={count += step}>{count} × 2 = {doubled}</button>
@if (count > 10) {
<p>That's a lot of clicks.</p>
}
</div>
<style>
.counter {
padding: 0.6rem 1.2rem;
border: 0;
border-radius: 999px;
background: var(--accent);
color: var(--on-accent);
font-weight: 600;
font-variant-numeric: tabular-nums;
cursor: pointer;
}
.counter:active {
scale: 0.97;
}
</style>
Figures
17.4KB
- Lithe 17.4 KB
- Svelte 22 KB
- Solid 20.5 KB
- Compose 119.7 KB
Lowest of the four.
47.5ms
- Lithe 47.5 ms
- Svelte 48.0 ms
- Solid 48.4 ms
- Compose 194.1 ms
Lowest of the four.
10.8ms
- Lithe 10.8 ms
- Svelte 12.9 ms
- Solid 10.1 ms
- Compose 64.0 ms
Solid is ahead here.
What you get
Small runtime, full toolbox
- 01
Static stays static
Pages are finished HTML before any script runs. Nothing interactive on a page? It ships no JavaScript. Just a search box? Only the search box wakes up, as an island.
Static pages and islands → - 02
Updates in place
Your component runs once. When a value changes, only the text or attribute that reads it updates. No virtual DOM, no diffing.
State and effects → - 03
Just Kotlin
Props, state and handlers are plain Kotlin, with the typed DOM of kotlin-browser. The client only carries what its components use.
Component files → - 04
A real template language
@if, @for with keys, @when, @await, @key, local @fun fragments, two-way bindings, <head> tags and scoped styles that take Kotlin values.
Control flow → - 05
Routing built in
window.route() follows the URL and matchRoute picks what to show. Links move without a reload, through the Navigation API where the browser has it.
Routing → - 06
Friends with Compose
Lithe components and Compose HTML composables mount each other. In a Kobweb site, a .lithe file under pages is a page, and apiData reads an API route.
Kobweb → - 07
Tooling that keeps up
A dev server that rebuilds on save and swaps markup text edits without a Kotlin compile, plus a language server for VS Code and IntelliJ IDEA.
Editors → - 08
Measured, not promised
Bundle size and load times are measured against Svelte, Solid and Compose on every change that can move them, and published as they come.
Performance →
Under the hood
From a file to the page
-
Compile
Each
.lithefile becomes plain Kotlin, one function per component, for the JVM and for the browser. -
Render
At build time, the components run on the JVM against an HTML writer and write the static page.
-
Hydrate
In the browser, the same components run on Kotlin/JS and adopt the nodes already there instead of building them again.
Get started
Up and running in a few minutes
- Add Lithe
The Gradle plugin compiles your
.lithefiles, the runtime does the rest. - Write a component
An
App.lithewith a<script kotlin>, some markup and, if you like, a<style>. - Run the dev server
It rebuilds on save, and edits to the markup text show up without a Kotlin compile.
plugins {
// Compiles the .lithe files of the project
id("io.github.ayfri.lithe") version "0.1.0"
}
kotlin {
sourceSets {
jsMain.dependencies {
implementation("io.github.ayfri.lithe:runtime-compose:0.1.0")
}
}
}
Works with VS Code IntelliJ IDEA Kobweb Compose HTML