How I use HTMX with Go(alexedwards.net)
285 points by gnabgib 17 hours ago | 85 comments
tl;dr: A walkthrough of building Go web apps with HTMX, focusing on a template rendering pattern using a shared `htmlRenderer` type that can serve either full pages or partials from the same template files, with assets embedded via `go:embed`. Key techniques include checking the `HX-Request` header to conditionally return partials vs. full pages (with a `Vary: HX-Request` response header), handling redirects via `HX-Redirect`, and configuring HTMX to swap error responses into `<body>`, disable history caching, and turn off attribute inheritance.
HN Discussion:
  • Enthusiastic endorsement of Go + HTMX stack, sharing complementary tools and workflows
  • HTMX works well for simple apps but breaks down for complex interconnected UIs
  • HTMX is a welcome return to simpler server-rendered web development over heavy JS frameworks
  • Practical tips for HTMX usage, like componentizing HTML generation on the backend
  • ~Adoption challenges arise from team/social resistance rather than technical merit