Htmx 4.0

The htmx team is very happy to announce the release of htmx 4.0.0! This is the culmination of 8 months of work (plus
agame) and we are very happy with the results.

The idea of htmx 4 started to germinate when I decided to createfixiand, in doing so, got
more familiar with thefetch()API and async programming in JavaScript. (htmx had always
usedXMLHttpRequestdue
to backwards compatibility issues.)

One chance evening I was contacted by Christian, who had some interesting ideas
aroundstreaming HTMLthat
got me thinking that moving the internals tofetch()would simplify things for him and for the library in general.After a bit of work I managed to get Michael and Alex on board, and we were off to the races.

Development has been very smooth. We started a port of fixi + the htmx test suite. Over time, we rediscovered why htmx
did many of the things that it did and moved our new implementation closer and closer to the old one. At this point
the behavioral differences between 2.x and 4.x are relatively small and where they do diverge we have made explicit
choices that we feel will put htmx-based applications in a good spot for
being100-year web services

Note that we are not marking 4.0 aslatestin NPM
because we do not want to force-upgrade users who are relying on non-versioned CDN URLs for htmx. Instead, 2.x will
remainlatestand the 4.0 line will remainnextuntil some point in early 2027. The website, however, will reference 4.0.

As mentioned above, htmx 4, from a user’s viewpoint, is almost identical to htmx 2. There are three major changes:

Internally, we migrated fromXMLHttpRequesttofetch()but that should be transparent for most users of htmx.

In htmx 2 many attributes were “inherited” by default. This allows you to place attributes on parent elements and
their behavior will apply to child elements. This behavior, which came from
theintercooler.jsdays, was inspired by CSS and, unsurprisingly, worked out about the same
as CSS: powerful but difficult to understand at times.

In htmx 4 attributes are not inherited unless youexplicitly say soby adding an:inheritedafter the attribute name:

This will be the largest upgrade burden in migrating from htmx 2 to htmx 4. To make things easier, we have provided
acommand line toolto find places you need to mark as inherited.

Note that attributes likehx-disinherit, etc. are no longer required and should be removed.

The events triggered by htmx 2 had grown organically over the life of the library and were not particularly well
organized, making it difficult to know exactly which event was fired when.