Clojure: Realtime collaborative web apps without ClojureScript
a year ago
- #Web Development
- #Clojure
- #Real-time
- A multiplayer web app was created without ClojureScript or user-written JavaScript, using the Datastar hypermedia framework.
- The app streams the entire <main> element from server to client every 200ms over SSE (Server Sent Events).
- Performance is maintained despite naive implementation (e.g., 1600-cell grid with individual on-click listeners) due to Datastar's efficient morph algorithm.
- Network efficiency is achieved through Brotli compression over SSE, offering high compression ratios (100-230:1).
- SSE is preferred over WebSockets for operational simplicity, better compression, and built-in HTTP features.
- Datastar allows for a React-like view = f(state) model but keeps the state function on the server.
- Example code demonstrates using Hyperlith (a mini-framework on Datastar) for handling SSE, compression, and more.
- The app inherently supports multiplayer functionality without additional code changes.
- Datastar is backend language and framework agnostic, making it versatile for various projects.