HTML over WebSockets: real-time SPAs with barely any JavaScript(en.andros.dev)
246 points by redbell 9 days ago | 193 comments
tl;dr: HTML over WebSockets (popularized by Phoenix LiveView) renders HTML on the server and pushes it to clients over a persistent bidirectional channel, eliminating the need for a JSON API, client-side rendering framework, or duplicated state. Advantages include a single language/codebase, real-time broadcast, and better XSS safety, at the cost of stateful servers, higher resource use per connection, and no offline support. The article surveys implementations across Elixir, Ruby, Python/Django, .NET, and PHP, and notes SSE as a cheaper one-way alternative when bidirectional communication isn't required.
HN Discussion:
  • ~SSE with standard HTTP is simpler and sufficient for most use cases instead of WebSockets
  • Historical credit correction: the technique predates Phoenix LiveView with Rails Sync
  • The approach is valid when matched to the right context and problem
  • This is just re-invention of older techniques like DHTML and ASP.NET Ajax
  • HTML-swapping has real drawbacks (lost focus, scroll jumps) and data-driven DOM models are preferable