Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Htmx Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-htmx-knowledge-patch-nevaberry-plugins)
---
name: htmx-knowledge-patch
description: htmx
version: "4.0.2"
license: MIT
metadata:
author: Nevaberry
---
# htmx Knowledge Patch
Load this skill when upgrading htmx or working with request behavior, triggers,
swaps, history, extensions, security settings, or web components.
The references retain examples and distinguish dated roadmap proposals from
released behavior.
## Reference index
| Reference | Topics |
| --- | --- |
| [Migration and configuration](references/migration-and-configuration.md) | Extension upgrades, module builds, inheritance, release policies and npm tags |
| [Events and JavaScript](references/events-and-javascript.md) | TypeScript, AJAX context, triggers, view transitions, lifecycle events, inline handlers and shadow roots |
| [Extensions and security](references/extensions-and-security.md) | SSE and WebSocket attributes, live bindings, downloads, extension files, origin allowlisting and stylesheet nonces |
| [History and caching](references/history-and-caching.md) | History restoration, GET cache separation, cache bypass and planned server-backed restoration |
| [Requests and validation](references/requests-and-validation.md) | DELETE parameters, confirmation, form validation, URL parameters and JSON forms |
| [Swaps and responses](references/swaps-and-responses.md) | Partial responses, swap API, morphing proposals, out-of-band swaps, response rules, scrolling and demos |
## Upgrade changes
### DELETE endpoint compatibility
htmx sends `DELETE` parameters in the query string by default. To retain
form-encoded bodies for existing DELETE endpoints, limit URL parameters to GET:
```js
htmx.config.methodsThatUseUrlParams = ["get"];
```
### Extension compatibility and removed files
Extensions have independent versions. htmx 2 requires an updated SSE extension,
though most 1.x extensions still work. The old `/dist/ext` files remain available
for existing CDN URLs. The `htmx-1-compat` extension restores most htmx 1
behavioral defaults during an upgrade.
4.0.1 removes the stale `hx-compat` and `hx-optimistic` files from `dist/ext`.
### SSE, WebSocket and live API migration
For 4.0.2, migrate `sse-*` and `ws-*` attributes to `hx-sse:*` and `hx-ws:*`.
Examples are `hx-sse:swap="message"` and `hx-ws:send`.
Starting in 4.0.2, load the `hx-live` extension before calling `htmx.live`;
the extension registers the API when it loads.
### Inheritance settings
Set `disableInheritance` to `true` to make inheritance opt-in, then use
`hx-inherit` on the ancestor to name the attributes descendants should inherit:
```html
<meta name="htmx-config" content='{"disableInheritance":true}'>
<div hx-target="#results" hx-inherit="hx-target">
<button hx-get="/results">Refresh results</button>
<div id="results"></div>
</div>
```
Starting in 4.0.1, `implicitInheritance` excludes HTTP verb attributes,
`hx-action`, and `hx-trigger`. Declare these on the elements that use them.
### Pending trigger cancellation
In 4.0.1, any trigger on the same element could cancel a pending `delay` or
`throttle`. Starting in 4.0.2, only triggers in the same `hx-trigger` value can
cancel it. An `hx-on` handler leaves the pending trigger in place.
```html
<input name="q" hx-get="/search" hx-trigger="keyup delay:300ms, change">
```
### Scrolling defaults
htmx scrolls instantly by default. Restore the 1.x smooth scrolling behavior
with `htmx.config.scrollBehavior = "smooth"`.
## Swaps and response handling
### Released partial response elements
htmx 2.0.11 backports the released `<hx-partial>` tag from htmx 4. Set `hx-target`
on each partial in the response to direct it to a separate element:
```html
<hx-partial hx-target="#status">Saved</hx-partial>
```
In 4.0.1, responses containing only partials leave the main body intact,
and partials honor `ignoreTitle`.
### Public swap API and out-of-band content
The public `htmx.swap()` replaces the internal `selectAndSwap()` and inserts
HTML using an htmx swap style:
```js
htmx.swap(document.getElementById("status"), "<strong>Saved</strong>", {
swapStyle: "innerHTML"
});
```
Wrap a standalone table row in a response `<template>` so the HTML parser
preserves it for an out-of-band replacement. Set
`htmx.config.allowNestedOobSwaps = false` to suppress out-of-band swaps nested
within the main response fragment and reuse marked fragments as page content.
### Render validation responses
htmx uses the first matching `code` regex in `htmx.config.responseHandling`.
Add a rule before the default `[45]..` rule to render a validation fragment
returned with status 422 and treat it as a normal response:
```js
htmx.config.responseHandling.unshift({ code: "^422$", swap: true, error: false });
```
## Requests, triggers and validation
### Delegated trigger filters
`from:` resolves its selector once, so listen on a stable ancestor when swaps
can replace descendants. In bracket filters, bare names resolve against the
triggering event first, then global scope; `this` is the element carrying
`hx-trigger`.
```html
<div hx-get="/summary" hx-trigger="click[target.matches('button.refresh')] from:body"></div>
```
### Confirmation and browser validation
`htmx:confirm` fires for every request trigger, including elements without
`hx-confirm`. Cancel it with `preventDefault()` and call
`event.detail.issueRequest()` after the user approves.
htmx blocks invalid form submissions by default. Set
`htmx.config.reportValidityOfForms = true` to also show the browser's validation
message and focus the first invalid input.
## History and cache behavior
On a history cache miss, the restoration request carries
`HX-History-Restore-Request: true` and expects a full page. If the server uses
`HX-Request` to choose between a full page and a fragment, set
`htmx.config.historyRestoreAsHxRequest = false` to omit that header from
restoration requests.
When you cannot set `Vary: HX-Request`, set
`htmx.config.getCacheBusterParam = true` to separate htmx GET cache entries from
browser navigations to the same URL. htmx appends
`org.htmx.cache-buster=<target-id>` to the GET URL.
## Security configuration
`selfRequestsOnly` defaults to `true`. To allow specific extra origins,
register `htmx:validateUrl` before disabling that setting and cancel requests
whose `event.detail.url` is outside the allowlist:
```js
document.body.addEventListener("htmx:validateUrl", (event) => {
const { sameHost, url } = event.detail;
if (!sameHost && url.origin !== "https://api.example.com") event.preventDefault();
});
htmx.config.selfRequestsOnly = false;
```
Set `inlineStyleNonce` before htmx initializes so its request-indicator
stylesheet carries the nonce from the page's Content Security Policy.
## JavaScript and web components
Use `dist/htmx.esm.js` for ESM, `dist/htmx.amd.js` for AMD, or
`dist/htmx.cjs.js` for CommonJS. The ESM build exports htmx as its default
export; `dist/htmx.js` remains available for a classic browser script.
Every property of `HtmxAjaxHelperContext` is optional, so `htmx.ajax()` can
supply just the options it needs:
```js
htmx.ajax("GET", "/status", { target: "#status" });
```
htmx's document scan skips shadow roots. After rendering component markup,
pass the root returned by `attachShadow()` to `htmx.process(root)`, including
when the root is closed.
`hx-target` resolves selectors within the current shadow root by default.
Use `hx-target="host"` to target the element hosting that root, or prefix a
selector with `global` to resolve it against the main document.