HTMX Partial Updates

Only the results div is swapped each second — no full page reload

What this demonstrates

  • Fragment endpointsGET /fragment and GET /fragment/diagnostics return raw HTML, no page wrapper
  • Controller without App — no polling state management; ctrl.RenderTemplate() used directly
  • Embedded template — HTMX layout is a Go string constant, no templates/ directory on the server
  • Concurrent safetyrenderAndCapture() mutex prevents buffer interleaving from simultaneous HTMX requests

Key HTMX attribute

<div id="results"
     hx-get="/fragment"
     hx-trigger="every 1s"
     hx-swap="innerHTML">

Server-side flow

GET /                     → full page with HTMX polling on #results
GET /fragment             → HTML fragment (schematic only)
GET /fragment/diagnostics → HTML fragment (diagnostics only)
POST /start|/stop         → toggle simulation, redirect /

The WASM demo below simulates this — JavaScript calls Go render functions directly. Run task go-example:09 to see real HTMX partial updates.


Live Demo (WASM)

Loading WASM...