The purpose of this guide is to provide instructions for migrations from htmx 1.x to htmx 2.x. We place a very high value on backwards compatibility, so in most cases this migrations should require very little, if any, work.
/dist/htmx.esm.js
/dist/htmx.amd.js
/dist/htmx.cjs.js
/dist/htmx.js
file continues to be browser-loadablehx-ws
and hx-sse
attributes, please upgrade to the extension versionshtmx.config.scrollBehavior
to 'smooth'
DELETE
requests to use a form-encoded body rather than parameters, revert
htmx.config.methodsThatUseUrlParams
to ["get"]
(it’s a little crazy, but DELETE
, according to the spec, should
use request parameters like GET
.)htmx.config.selfRequestsOnly
to false
hx-on
attributes to their hx-on:
equivalent: <button hx-get="/info" hx-on="htmx:beforeRequest: alert('Making a request!')
htmx:afterRequest: alert('Done making a request!')">
Get Info!
</button>
becomes: <button hx-get="/info" hx-on:htmx:before-request="alert('Making a request!')"
hx-on:htmx:after-request="alert('Done making a request!')">
Get Info!
</button>
Note that you must use the kebab-case of the event name due to the fact that attributes are case-insensitive in HTML.
htmx.makeFragment()
method now always returns a DocumentFragment
rather than either an Element
or DocumentFragment
selectAndSwap
method from internal API, it was removed and replaced with swap
method,
which is available from both internal and public htmx APIsTo do a swap using new method, you need to simply use
let content = "<div>Hello world</div>"; // this is HTML that will be swapped into target
let target = api.getTarget(child);
let swapSpec = api.getSwapSpecification(child);
api.swap(target, content, swapSpec);
swap
method documentation is available on JS API Reference
IE is no longer supported in htmx 2.0, but htmx 1.x continues to support IE and will be supported for the foreseeable future.
This is the official htmx 1.x -> 2.x upgrade music: