The Resurgence of Hypermedia Systems: Engineering Modern UIs with HTMX 3.0
For the past decade, the industry consensus on web architecture was settled: a "modern" application requires a thick Single Page Application (SPA) built in React, Vue, or Angular, communicating with a stateless JSON API. We accepted the complexity of state synchronization, the heavy bundle sizes, and the "JavaScript tax" as the necessary cost of progress.
But the tide is shifting. With the release of HTMX 3.0, a growing cohort of developers is rediscovering the power of the original architectural style of the web: Hypermedia.
By returning to "Hypermedia as the Engine of Application State" (HATEOAS), we can build rich, interactive user interfaces with a fraction of the complexity. In this post, we’ll explore the resurgence of hypermedia systems, type-safe patterns for HTMX, and why the Go + HTMX stack is becoming a favorite for performance-critical applications.
The "SPA Fatigue" and the Return to the Server
The shift toward SPAs was driven by the need for UX fluidity—the ability to update parts of a page without a full reload. However, this introduced a massive architectural split. Developers now had to manage two separate applications: the frontend state and the backend source of truth.
HTMX challenges the premise that "dynamic" requires "JSON." It allows you to access AJAX, CSS Transitions, WebSockets, and Server Sent Events directly in HTML, using attributes. Instead of exchange data (JSON) and turning it into DOM elements on the client, you exchange HTML fragments.
The Core Philosophy: Moving State back to the Server
In a hypermedia-driven architecture, the server remains the single source of truth for both data and the UI state. When a user clicks a "Delete" button, the server doesn't just return {"success": true}; it returns the new HTML state of the list.
Architecting with HTMX 3.0: High-Level Patterns
HTMX 3.0 brings refined event handling and better integration with modern browser APIs. When building production-scale systems, simple "swap" operations aren't enough. We need structured patterns.
1. The Fragment-Based Routing Pattern
Instead of full-page refreshes, use the hx-boost attribute to intercept standard anchor tags. HTMX will fetch the page via AJAX, swap the <body> content, and update the URL using the History API. This gives you SPA-like speed while maintaining the simplicity of a Multi-Page Application (MPA).
2. OOB (Out-of-Band) Swaps
One of the most powerful features of HTMX is the ability to update multiple parts of a page in a single request.
<!-- The primary response -->
<div id="cart-items">
<li>New Item Added!</li>
</div>
<!-- An extra fragment to update the navbar counter -->
<div id="cart-count" hx-swap-oob="innerHTML">
5
</div>
This eliminates the need for complex client-side state management (like Redux or Pinia) for cross-component communication.
Type-Safe HTMX: Bridging the Gap
A common criticism of hypermedia systems is the lack of "contract" safety. In an SPA, you can generate TypeScript interfaces from your OpenAPI/Swagger spec. In HTMX, you are sending HTML strings. How do we ensure the backend returns what the frontend expects?
The "Templates as Code" Approach
In the Go ecosystem, tools like Templ have revolutionized this. Templ allows you to write HTML components as type-safe Go code.
// cart_component.templ
package components
templ CartCount(count int) {
<span id="cart-count" class="badge">
{ strconv.Itoa(count) }
</span>
}
By using type-safe templates, if you change a data structure in your Go backend, the compiler will catch broken references in your HTML templates. This creates a "Type-Safe Hypermedia" loop that is arguably more robust than JSON-to-TS mapping because there is no serialization boundary to manage.
The "HyperGo" Stack: Why Go and HTMX?
The Go + HTMX stack (often called the "BETH" or "GOTH" stack) has gained viral traction. Why?
- Concurrency: Go’s goroutines make it trivial to handle long-running hypermedia streams (SSE/WebSockets).
- Binary Distribution: You can bundle your templates and static assets into a single executable. No more
node_modulesin production. - Low Latency: Since the server generates the HTML, the Time to First Byte (TTFB) is critical. Go’s efficiency ensures that fragment generation takes microseconds.
Example: A Zero-JS Search Filter
Here is how elegantly a Go + HTMX handler looks:
func SearchHandler(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("q")
results := database.Search(query)
// Check if it's an HTMX request
if r.Header.Get("HX-Request") == "true" {
// Return only the partial fragment for the table body
components.SearchResultsTable(results).Render(r.Context(), w)
return
}
// Otherwise, return the full page layout
components.SearchPage(results).Render(r.Context(), w)
}
On the frontend:
<input type="text" name="q"
hx-get="/search"
hx-trigger="keyup changed delay:500ms"
hx-target="#search-results"
placeholder="Search users...">
<tbody id="search-results">
<!-- Results load here -->
</tbody>
Zero-JS Frontend Strategies: Is it Really No JavaScript?
The goal of HTMX isn't necessarily "No JavaScript," but "No Custom JavaScript." By using a declarative attribute-based library, you reduce the surface area for bugs.
However, for complex client-side interactions (like a signature pad or a drag-and-drop file uploader), HTMX works best when paired with Alpine.js. Alpine follows the same philosophy: it keeps the logic in the HTML.
This combo—HTMX for server communication and Alpine for "sprinkles" of client logic—allows you to build 99% of modern web requirements without ever touching a build tool like Webpack or Vite.
The Future of the Hypermedia System
HTMX 3.0 isn't a step backward; it's a correction. We are moving away from the "distributed monolith" of JSON APIs and thick clients toward a more cohesive, resilient architecture.
When should you choose HTMX?
- Internal tools and CRUD-heavy dashboards.
- Content-centric platforms (Blogs, E-commerce, Social Media).
- Teams that want to move fast without the overhead of two separate build pipelines.
When should you stay with an SPA?
- Offline-first applications.
- Highly iterative graphical editors (like Figma or Canva).
- Applications with extremely complex client-side state (like a local-first DAW).
Conclusion
The resurgence of Hypermedia Systems represents a return to the fundamentals of the Web. By leveraging HTMX 3.0 and type-safe backend languages like Go, we can create applications that are faster to develop, easier to maintain, and significantly more performant for the end-user.
If you’re tired of the constant churn of JavaScript frameworks, it’s time to look back at HTML. You might be surprised at how much power was there all along.
Ready to try the HyperGo stack? Start by checking out the HTMX Documentation and the Templ project. The web is simpler than you think.
Top comments (0)