htmx
Overview
htmx extends HTML with attributes (hx-get, hx-post, hx-swap, …) so servers return partial HTML instead of building a heavy client SPA. It pairs naturally with Django, Rails, Laravel, Go templates, or any backend that can render HTML fragments.
Key concepts
- Hypermedia-driven: UI state transitions as HTTP + HTML.
- Partial swaps: Replace fragments of the DOM from responses.
- Triggers: Events, polling, WebSockets/SSE extensions (
htmxextensions). - Out-of-band swaps:
hx-swap-oobfor multi-fragment updates. - Security: CSRF tokens, proper
Content-Type, and server-side validation remain required.
hx request flow
Sample: button loads fragment
<button hx-get="/fragments/stats" hx-target="#stats" hx-swap="innerHTML">
Refresh stats
</button>
<div id="stats"></div>
References
- htmx Documentation
- htmx Essays: Hypermedia
- MDN: Fetch / forms
- W3Schools: AJAX intro (conceptual parallel)