12 ms·
But it is simple :) The underlying technology might be more complex, but the library is solid, it's trivial to update any part of the page once you have the lib
by jonathrg 2y ago
But it is simple :) The underlying technology might be more complex, but the library is solid, it's trivial to update any part of the page once you have the libraries set up, and you don't need to write any javascript. Works for me!
- maddalax 2y agowhy websockets and not just SSE + XHR? Or even just XHR Edit: SSE*
- jonathrg 2y agoIt is SSR, in the sense that the server sends HTML over the websocket. HTMX swaps out content based on the element id. Doc: https://v1.htmx.org/extensions/web-sockets/ https://v1.htmx.org/extensions/web-sockets/ If you mean SSE, then yes that would work just as well (unless you need the bidirectionality for the client to modify some aspect of the connection after the page has loaded). There is an htmx-sse extension too. I'm not sure how XHR alone would let you automatically get backend state changes reflected to the frontend. You can poll one or more endpoint, but that's more complicated to get right and less efficient.
- maddalax 2y agoSorry yes I meant SSE, mistyped!
- jonathrg 2y ago> Mostly just thinking that XHR to mutate (form submissions, etc) and then SSE to send the updated DOM elements would be a good combo Yes, that's basically the idea.
- maddalax 2y agoMostly just thinking that XHR to mutate (form submissions, etc) and then SSE to send the updated DOM elements would be a good combo
- klibertp 2y ago> I'm not sure how XHR alone would let you automatically get backend state changes reflected to the frontend. Long polling. Check out (history of) "Comet": https://en.wikipedia.org/wiki/Comet_(programming)#Implementations https://en.wikipedia.org/wiki/Comet_(programming)#Implementa...
- jpc0 2y agoSSR is effectively long polling with a standardised format and is browser native. Also writing a client ontop of an existing HTML client is very very easy so even when not on web it's east to implement...
- ctvo 2y ago> But it is simple :) I think you may mean easy. It may be _easy_, but it's not simple. There are so many more moving pieces, failure modes, operational issues now to consider. Websocket connections aren't free.
- jonathrg 2y agoI guess I just have to disagree. My experience is that it is robust, and removes an entire category of problems that appear when your state is spread across the back- and frontend. As someone else mentioned, SSE is a somewhat simpler protocol that achieves the same purpose. Same idea though.