Clojure: Realtime collaborative web apps without ClojureScript

https://news.ycombinator.com/rss Hits: 16
Summary

Clojure: Realtime collaborative web apps without ClojureScript07 Apr 2025Last week I made a fun little multiplayer web app. I've embedded it below:A few things to note about this web app:It is streaming the whole <main> element of the page from the server to the client every 200ms over SSE (server sent events).It has zero ClojureScript.It has zero user written JS.It uses a tiny 11.4kb (brotli compressed) hypermedia framework called Datastar.What about performance?Surely sending down the whole main body on every change is terrible for performance?!There's no canvas here. There's no SVG. There's just a 1600 cell grid, each cell with it's own on-click listener. This is an incredibly naive implementation. Partly, to show how well it performs. Your CRUD app will be fine.Under the hood Datastar uses a very fast morph algorithm that merges the old <main> fragment with the new <main> fragment only updating what has changed.Update: It was pointed out on the Datastar discord that there is no reason not to leverage HTML bubble up events. Honestly, I completely forgot you could do this (too much time with react I guess?). So now there's only one top level event listener. I've bumped the number of cells to 2500 to keep the volume of data over the wire roughly the same.What about the network?Surely sending down the whole main body on every change is terrible for bandwidth?! Turns out streaming compression is really good. Brotli compression over SSE (server sent events) can give you a 100-230:1 compression ratio over a series of backend re-renders. The compression is so good that in my experience it's more network efficient and more performant that fine grained updates with diffing (without any of the additional complexity). This approach also avoids the additional challenges of view and session maintenance.Isn't this just another Phoenix Live View clone?No, it's much simpler than that. There's no connection state, server side diffing or web sockets. There's no reason the client h...

First seen: 2025-04-11 01:46

Last seen: 2025-04-11 16:49