html★ works with any server that returns HTML. No special setup required for basic usage.

Request Headers

Every html★ request includes the X-Requested-With: htmlstar header. This lets the server detect html★ requests and respond accordingly — for example, returning a fragment instead of a full page, or applying the POST-redirect-GET pattern via response headers.

data-send-headers Attribute

Add data-send-headers to opt in to sending target and select information to the server. This is useful for server-side fragment rendering, where the server can tailor its response based on which element will receive the content:

With data-send-headers, the server receives the CSS selectors for both the target element and the selected fragment, enabling it to render only the relevant portion of the page.

HeaderValueDescription
X-Requested-WithhtmlstarAlways sent on every html★ request
X-HTMLStar-TargetCSS selectorSent when data-send-headers is present; identifies the target element
X-HTMLStar-SelectCSS selectorSent when data-send-headers is present and data-select is set

Response Headers

html★ recognizes special response headers that allow the server to control client-side behavior. These headers are checked after every successful fetch and take effect before the normal content swap.

HeaderValueEffectUse Case
X-HTMLStar-RedirectURLClient-side navigation to the given URLPOST-redirect-GET pattern, login flows
X-HTMLStar-RefreshtrueFull page reloadSession expiry, major state changes
X-HTMLStar-RetargetCSS selectorOverride which element receives the swapped contentShow errors in a toast, redirect response to a different panel

X-HTMLStar-Redirect

The server can trigger a client-side navigation by setting X-HTMLStar-Redirect to a URL. html★ will navigate the browser to that URL instead of swapping the response body. This is the html★ equivalent of an HTTP redirect, but it happens on the client side, preserving SPA-like behavior.

X-HTMLStar-Retarget

The server can dynamically change which element receives the swapped content by setting X-HTMLStar-Retarget to a CSS selector. html★ will look up that selector on the page and swap the response into the matched element instead of the original target. If the selector does not match any element, the original target is used as a fallback.

Ruby on Rails

Django

Laravel

Go

Summary

ApproachServer ChangesCachingBest For
Full PagesNoneSimpleMost projects, static sites
Server FragmentsRequiredNeeds Vary headerLarge pages, bandwidth optimization

Recommendation: Start with full pages (Pattern A). It's simpler, more robust, and handles progressive enhancement automatically. Only add server-side fragment detection if you have a specific performance need.

For more advanced server patterns, see the Content Negotiation, Fragment Rendering, and Component Registry guides.