HeadlinesBriefing favicon HeadlinesBriefing.com

HTML over WebSockets: Real-time SPAs Without JavaScript

Hacker News •
×

Building a SPA typically requires a JavaScript framework, a JSON API, and two codebases. HTML over WebSockets offers a simpler approach: the server sends pre-rendered HTML over a permanent bidirectional channel, and the client just places it. All rendering logic stays in the back-end, eliminating contracts and APIs.

Chris Mc Cord introduced this pattern at Elixir Conf 2019 with Phoenix Live View, building a real-time Twitter clone with no rendering JavaScript. The idea has since inspired implementations in other languages. The client still uses JavaScript, but only to open a WebSocket and place received HTML—no framework needed.

Advantages include a single rendering engine, no API needed, server-side state, real-time broadcast, less latency, and improved security against XSS. Drawbacks are higher server resource use, scaling complexity, offline failure, and a steeper learning curve for WebSocket servers.

Frameworks like Phoenix Live View, Django Live View, and others now support this pattern. It's ideal for real-time apps like chats or dashboards where bidirectional communication is critical.