News for hackers. Stuff that matters.
Re:Building a Single-Page App with Htmx by jonathrg on Monday October 07, 2024 @04:38PM (#41770770)
It 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/

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.

Re:Building a Single-Page App with Htmx by klibertp on Monday October 07, 2024 @06:29PM (#41771784)
> 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)#Implementa...

Re:Building a Single-Page App with Htmx by jpc0 on Tuesday October 08, 2024 @08:21AM (#41776532)
SSR 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...

Re:Building a Single-Page App with Htmx by maddalax on Monday October 07, 2024 @04:58PM (#41770968)
Mostly just thinking that XHR to mutate (form submissions, etc) and then SSE to send the updated DOM elements would be a good combo
Re:Building a Single-Page App with Htmx by maddalax on Monday October 07, 2024 @04:49PM (#41770892)
Sorry yes I meant SSE, mistyped!
Re:Building a Single-Page App with Htmx by jonathrg on Monday October 07, 2024 @05:02PM (#41771014)
> 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.