<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl" -->

---
title: Compose & kotlinx.html | daily.dev
description: Jake Wharton describes a technique for keeping server-rendered HTML admin dashboards fresh without adopting a client-side framework. Using Ktor and...
canonical: https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Compose & kotlinx.html | daily.dev
og:description: Jake Wharton describes a technique for keeping server-rendered HTML admin dashboards fresh without adopting a client-side framework. Using Ktor and...
og:url: https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl
og:image: https://api.daily.dev/og/posts/bwNVtjbSL.png
og:image:alt: Compose & kotlinx.html
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Compose & kotlinx.html

**[Jake Wharton](https://daily.dev/sources/jakewharton)** · 4 min read · 3 upvotes · 1 comments

## Summary

Jake Wharton describes a technique for keeping server-rendered HTML admin dashboards fresh without adopting a client-side framework. Using Ktor and kotlinx.html for static markup, he pipes state changes through Molecule (Cash App's Compose-based state management library) over a WebSocket, streaming HTML fragments to the browser and patching the DOM with Idiomorph. He also outlines production considerations: multiplexing updates over a single connection, preferring server-sent events over WebSockets for unidirectional data, and deciding whether composition state is connection-scoped or shared.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://jakewharton.com/compose-and-kotlinx-html>

## Questions this post answers

### How can I keep server-rendered HTML pages updated in real time without switching to a client-side framework like React or Compose for HTML?

Use a Ktor WebSocket endpoint combined with Molecule to run a Compose-style composition that manages a single state value over time, rendering it into an HTML fragment string via kotlinx.html and streaming it to the client. On the client, feed incoming messages into the DOM using Idiomorph's morph function so unchanged form fields and interactive elements are preserved instead of replaced.

_daily.dev surfaces practical Kotlin server-rendering patterns like this for developers avoiding heavy client-side frameworks._

### Should I use WebSockets or server-sent events for pushing one-way HTML fragment updates from a Kotlin backend to the browser?

Server-sent events are the better fit when updates flow only from server to client, because SSE multiplexes over a single HTTP/2 connection and provides built-in framing that separates the event name from its payload. WebSockets are bidirectional and lack that framing, requiring a custom envelope format if multiple page sections need targeted updates.

_Developers weighing SSE against WebSockets for live UI updates can track these tradeoffs on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@agustinbarrientos** · 0 upvotes

> A bidirectional socket doesn't make sense for this demo. I'd test reconnect ordering before changing transports. An older fragment winning after the client returns would be a nasty failure to debug.

## Similar posts on daily.dev

- [Exploring Compose HTML for Server Side Rendering](https://daily.dev/posts/exploring-compose-html-for-server-side-rendering-mpyptshna) · JetBrains · 4 upvotes · 0 comments
- [Kotlin Weekly \#528](https://daily.dev/posts/kotlin-weekly-528-jxzpknxgn) · Kotlin Weekly · 2 upvotes · 0 comments
- [Getting Started with Slack Circuit Framework for Jetpack Compose](https://daily.dev/posts/getting-started-with-slack-circuit-framework-for-jetpack-compose-ijb52owpv) · ProAndroidDev · 0 upvotes · 0 comments
- [HTML over WebSockets: real-time SPAs with barely any JavaScript](https://daily.dev/posts/html-over-websockets-real-time-spas-with-barely-any-javascript-xef6zsuxl) · Hacker News · 2 upvotes · 0 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#kotlin](https://daily.dev/tags/kotlin), [#jetpack-compose](https://daily.dev/tags/jetpack-compose), [#ktor](https://daily.dev/tags/ktor)

[View this post on daily.dev](https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Compose \u0026 kotlinx.html","url":"https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl"},"datePublished":"2026-08-27T02:03:48.129Z","dateModified":"2026-09-14T07:43:32.090Z","description":"Jake Wharton describes a technique for keeping server-rendered HTML admin dashboards fresh without adopting a client-side framework. Using Ktor and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/783b359bc344ce8763770516ac461830?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/783b359bc344ce8763770516ac461830?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Jake Wharton","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Jake Wharton","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/jakewharton"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"webdev,kotlin,jetpack-compose,ktor","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Jake Wharton","item":"https://daily.dev/sources/jakewharton"},{"@type":"ListItem","position":3,"name":"Compose \u0026 kotlinx.html"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl","comment":[{"@type":"Comment","text":"A bidirectional socket doesn’t make sense for this demo. I’d test reconnect ordering before changing transports. An older fragment winning after the client returns would be a nasty failure to debug.","datePublished":"2026-08-27T17:36:04.153Z","url":"https://daily.dev/posts/bwNVtjbSL#c-CKviF6hIZ","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/compose-kotlinx-html-bwnvtjbsl#faq","mainEntity":[{"@type":"Question","name":"How can I keep server-rendered HTML pages updated in real time without switching to a client-side framework like React or Compose for HTML?","acceptedAnswer":{"@type":"Answer","text":"Use a Ktor WebSocket endpoint combined with Molecule to run a Compose-style composition that manages a single state value over time, rendering it into an HTML fragment string via kotlinx.html and streaming it to the client. On the client, feed incoming messages into the DOM using Idiomorph's morph function so unchanged form fields and interactive elements are preserved instead of replaced. daily.dev surfaces practical Kotlin server-rendering patterns like this for developers avoiding heavy client-side frameworks."}},{"@type":"Question","name":"Should I use WebSockets or server-sent events for pushing one-way HTML fragment updates from a Kotlin backend to the browser?","acceptedAnswer":{"@type":"Answer","text":"Server-sent events are the better fit when updates flow only from server to client, because SSE multiplexes over a single HTTP/2 connection and provides built-in framing that separates the event name from its payload. WebSockets are bidirectional and lack that framing, requiring a custom envelope format if multiple page sections need targeted updates. Developers weighing SSE against WebSockets for live UI updates can track these tradeoffs on daily.dev."}}]}
```

