Extensions

htmx 4 ships 17 official extensions (Server-Sent Events, WebSockets, preloading, head merging and more), and Rizzy has four of its own. Using one takes three things that must line up:

  1. its script must load after htmx;
  2. if htmx.config.extensions (the allow-list) is set, it must contain the extension’s registered name, which is often not its file name: hx-sse.js registers as sse, hx-ws.js as ws, hx-preload.js as preload;
  3. the allow-list must keep Rizzy’s own extensions.

When any of these is wrong, htmx skips the extension silently. Rizzy takes care of all three.

Enabling extensions

Program.cs
builder.Services.AddHtmx(o =>
{
    o.UseExtensions(HtmxExtension.Sse, HtmxExtension.Preload);
});
AppLayout.razor
<head>
    ...
    <RzHeadOutlet />
    <RzScripts />
</head>

<RzScripts /> renders, in this order:

  1. htmx, from jsDelivr for the version Rizzy is tested with (HtmxAssets.Version), with a subresource integrity hash;
  2. rizzy.js (Rizzy’s own extensions and diagnostics), from RizzyConfig.ClientScriptUrl;
  3. each enabled extension, also with its integrity hash.

Every script carries the request’s CSP nonce, so a nonce-based Content Security Policy works unchanged.

Then use the extension’s attributes, ideally through the typed builder:

@* Connects on load (hx-trigger chooses when to connect), swaps unnamed messages into the div and
   closes when the server sends an event named "done". Named events are dispatched as DOM events. *@
<div @attributes="@(Hx.SseConnect("/notifications").SseClose("done"))"></div>

<a href="/reports" @attributes="@(Hx.Get("/reports").Preload())">Reports</a>

The allow-list

By default htmx accepts every extension that registers, and Rizzy writes no allow-list.

  • If you set HtmxConfig.Extensions yourself, Rizzy adds its own four extensions and every enabled extension to your list, so none of them is rejected.
  • Set RestrictExtensions = true to allow only the extensions Rizzy knows about: its own, the enabled ones and any you list in Extensions. A script that sneaks in another extension is then rejected by htmx.
builder.Services.AddHtmx(o =>
{
    o.UseExtensions(HtmxExtension.Preload);
    o.RestrictExtensions = true;
    // htmx.config.extensions = "rizzy-antiforgery, rizzy-nonce, rizzy-streaming, rizzy-confirm, preload"
});

Extension settings

Several extensions read their own section of htmx.config. Set them with Set(key, value); the value is written into the meta tag as JSON (camelCase). Keys that an HtmxConfig property already writes (mode, extensions, …) are rejected with an error that names the property to use instead:

builder.Services.AddHtmx(o => o
    .UseExtensions(HtmxExtension.Sse, HtmxExtension.HistoryCache, HtmxExtension.Preload)
    .Set("sse", new { reconnect = true, reconnectDelay = 1000 })
    .Set("historyCache", new { size = 20 })
    .Set("preload", new { boostEvent = "mouseover" }));

Where the scripts come from

HtmxConfig.Scripts controls <RzScripts />:

OptionDefaultDescription
BaseUrljsDelivr URL of htmx.org@<tested version>/dist/Where htmx.min.js and ext/<name>.min.js are loaded from. Point it at your own copy (for example /lib/htmx/) to serve htmx yourself.
MinifiedtrueLoad the .min.js files.
Integritynull (automatic)Add SRI hashes (and crossorigin="anonymous") for the pinned version. Automatic means only for the default jsDelivr URL, because a copy you serve yourself may be another version, which the browser would refuse to run. Set true for your own copy of the same version.
IncludeHtmxtrueLoad htmx itself. Set to false if your layout or bundler already loads it.
builder.Services.AddHtmx(o => o.Scripts = new HtmxScriptOptions { BaseUrl = "/lib/htmx/" });

The Rizzy script itself is configured on RizzyConfig: ClientScriptUrl (default /_content/Rizzy/js/rizzy.js). A root-relative URL gets the app’s path base, so the script loads on nested URLs such as /account/sign-in and under a virtual directory; absolute and relative URLs are used as given. Before 6.0.0-preview.4 the default was relative and broke on nested URLs without <base href="/">.

Third-party and your own extensions

Describe the extension with HtmxExtension.Custom(name, scriptUrl). It joins the allow-list and, when you give a script URL, <RzScripts /> loads it after the official ones:

o.UseExtensions(HtmxExtension.Custom("my-ext", "/js/my-ext.js"));

When something is wrong

rizzy.js reports problems on the browser console when the page loads:

  • htmx rejected an extension because the allow-list does not name it (including Rizzy’s own, if you set Extensions without UseExtensions).
  • An extension enabled on the server never registered, usually because <RzScripts /> is missing from the root layout or its script was not loaded. rizzy.js tracks registrations from the moment it loads, so if you write the script tags yourself, load extensions after rizzy.js; one loaded before it works but is reported here.

Set HtmxConfig.RizzyDiagnostics = false to silence these checks.

Official extensions

ExtensionHtmxExtensionRegistered nameWhat it doesTyped API
hx-sseSsesseServer-Sent EventsHx.SseConnect, SseClose; HtmxEvents.Sse.*
hx-wsWswsWebSocketsHx.WsConnect, WsSend; HtmxEvents.Ws.*
hx-preloadPreloadpreloadPreloads boosted links (on mousedown by default) and hx-preload elementsHx.Preload
hx-headHeadhx-headMerges <head> elements from responsesHx.Head, Preserve; HtmxEvents.Head.*
hx-promptPrompthx-prompthtmx 2’s hx-promptHx.Prompt; HtmxRequest.Prompt; HtmxEvents.Prompt.Answered
hx-liveLivehx-liveReactive hx-live expressionsHx.Live
hx-pendingPendinghx-pendingShows a template in the target while a request runsHx.Pending
hx-ptagPTagptagPolling tags: skip unchanged contentHx.PTag; HtmxRequest.PTag; Response.Htmx().PTag(...)
hx-targetsTargetshx-targetsOne response, several targetsHx.Targets
hx-browser-indicatorBrowserIndicatorbrowser-indicatorBrowser’s own loading indicatorHx.BrowserIndicator; Set("boostBrowserIndicator", true)
hx-cspCsphx-cspNonce-gated htmx processing; an alternative to Rizzy’s rizzy-nonceHx.Nonce; HtmxEvents.Csp.*
hx-multipartMultiparthx-multipartStreamed multipart responsesHx.MultipartConnect, MultipartClose; HtmxRequest.LastPartId; HtmxEvents.Multipart.*
hx-upsertUpsertupsertupsert swap styleHx.Swap("upsert ...")
hx-downloadDownloaddownloadFile downloads with progressHx.Swap("download"); Response.Htmx().Download(url); HtmxEvents.Download.*
hx-history-cacheHistoryCachehistory-cachehtmx 2-style history cacheHx.History(false); Set("historyCache", ...); HtmxEvents.HistoryCache.*
htmx-2-compatHtmx2Compatcompathtmx 2 event names and behavior
hx-alpine-compatAlpineCompatalpine-compatAlpine.js on swapped and morphed content

Rizzy’s own extensions, always loaded with rizzy.js: rizzy-antiforgery, rizzy-nonce, rizzy-streaming and rizzy-confirm (HtmxExtension.Rizzy).

Extensions that change the request’s fetch

Preload serves a click from a response it fetched on mousedown, and other extensions may wrap the request’s fetch function. Rizzy’s streaming extension keeps whatever they install and streams the final response, so [StreamRendering] pages still stream alongside them.