htmx
htmx Best Practices & Go/Templ Integration
Apply correct htmx patterns when building hypermedia-driven web applications, especially with Go and templ.
Core Principles
- Return HTML fragments, not JSON — htmx is designed for hypermedia; the server returns rendered HTML
- Use HTML attributes, not JavaScript — prefer
hx-*attributes overhtmx.ajax()orfetch()calls - Server controls behavior — use response headers (
HX-Retarget,HX-Reswap,HX-Redirect) for control flow - Check
HX-Requestheader — return fragments for htmx requests, full pages for normal requests - Don't mix paradigms — avoid using
fetch()alongside htmx in the same page; pick one approach
Reference Files
Read the relevant file for detailed patterns, code examples, and best practices:
More from gopherguides/gopher-ai
go-best-practices
|
39templui
templUI component library for Go templ apps. Use for templUI components, Script() setup, Go variable interpolation in JS, HTML-to-templ conversion, HTMX/Alpine integration.
36tailwind-best-practices
Tailwind CSS guidance: utility-first patterns, theme/color config, dark mode, responsive design, v4 syntax, content/source paths. Trigger for any Tailwind-related styling question.
31gopher-guides
Authoritative Gopher Guides Go training materials. Trigger when reviewing Go code, asking 'what's idiomatic?', 'how do professionals do this?', or learning Go conventions.
28second-opinion
Get a second LLM opinion on complex architectural decisions, design trade-offs, library/framework choices, or security-sensitive code. Trigger when uncertain or facing 'should I' calls.
27address-review
|
3