Live HTML Over SSE With app.Render and htmx
A support team works from a shared queue page that polls the server every five seconds. The queue is never quite current, so two agents regularly claim the same ticket within those five seconds, and one of them finds out later that the work was wasted. Meanwhile thirty open tabs ask the server 360 times a minute whether anything happened. Nearly always, nothing did.
Server-Sent Events fix both, and pushing HTML instead of JSON keeps one
rendering layer: the fragment comes from the same Go template as the page, and
htmx swaps it in with no JavaScript of your own. But c.Render writes only
into the response at hand, while one agent's claim has to reach thirty other
streams. app.Render writes a template through the
configured view engine into any io.Writer.
I built the live queue on it: each update rendered once, numbered, replayed
after a reconnect. On the way, an htmx settle delay lost every claim in a
headless browser and a later request overwrote a stored form value. app.Render
wraps fragments in the page layout unless you pass "", and one reconnect path
arrives without Last-Event-ID. Each comes with its fix.
