How I use HTMX with Go

294 points · 93 comments on HN · read original →

Points and comments are a snapshot, not live.

Alex Edwards shares patterns for combining HTMX with Go's html/template package for server-side rendering.

Edwards demonstrates structuring Go web apps with HTMX using embedded templates, partials, and a renderer that handles both full-page and partial HTML responses. He covers template organization with base, page, and partial files, embedding static assets via Go's embed directive, and a htmlRenderer type that clones and extends shared templates. The tutorial builds a user search feature with HTMX attributes for dynamic filtering, and addresses redirects, errors, and configuration settings for HTMX in Go applications.

What commenters are saying

Commenters overwhelmingly praise the Go + HTMX combination, with many sharing their own stacks and tools. Several recommend pairing HTMX with a-h/templ for type safety, sqlc for SQL code generation, and Datastar as an alternative. Some note HTMX's complexity grows with app size, and a few suggest hyperscript for DOM manipulation without server round-trips. The thread shows strong affection for Alex Edwards' teaching style, with multiple readers citing his books as foundational to learning Go web development.