History, errors, and enhancement
Boost links and forms
Enhance ordinary navigation and submission while preserving the original HTML behavior without JavaScript.
Adding HTMX attributes to every link and form gets tedious fast. hx-boost intercepts ordinary navigation and submission while keeping the native fallback:
<main hx-boost="true">
<a href="/tasks">Tasks</a>
<form action="/search" method="get">
<input name="q" type="search">
<button>Search</button>
</form>
</main>
A boosted same-origin link sends a GET to its href, swaps the response into <body> with innerHTML by default, scrolls to the top, and pushes the URL into history. A boosted form uses its action and method, but does not push a URL unless you request that separately.
The server should return complete pages for boosted navigation. HTMX can update the document title and extract body content. Direct navigation and JavaScript-disabled browsing receive the same useful response.
hx-boost is inherited. Set hx-boost="false" on a child that must keep normal navigation: downloads, logout flows, third-party links. Only same-origin, non-anchor links are boosted.
Inspect HX-Boosted: true on the server when you need rendering context. Never treat it as authorization. A boosted request is still a normal HTTP request someone could replay.
Boosted forms behave like boosted links in one important way: they still submit to the action URL with the declared method. A GET search form replaces the body content with results. A POST form replaces body content with whatever the server returns, often a redirect target rendered as a full page fragment.
If a form should not replace the entire body, do not rely on boost alone. Put hx-boost="false" on that form and use explicit hx-target instead.
Test direct navigation, refresh, Back, and Forward after enabling boost on a region. Boosted pages should feel faster without breaking bookmarking or the no-JS path.
Lesson completed