Htmx 2.0.4 Released
github.com
github.com
For me, I've been able to get turbo style links with the boost to get nice page transitions. I can also see how I could use the class-tools extension to enable buttons to open dialogs etc.
I'm curious to see when people say they needed an SPA for interactivity, what interactive features Htmx can already do and when do we need to break out some JS.
An example that I think needs JS is a copy paste button.
One example is incremental filtering: I added an input field, and made it (a few ms after the last value change) load the same page the user is already on with a query parameter that filters the items in the response. Then I just replace the list of items with the contents from the response, ignoring the rest of the page.
It's a bit wasteful perhaps, but all this took just a few lines of HTML.
But I want things like an on-site calculator. I load in products and prices, users can adjust sliders to change the quantity and relevant number is calculated. I don't want to use HTMX for this to call the server each time, I want instant reactivity and state in the frontend maintained so when the user has tweaked as necessary they can just check out.
HTMX does not fit this use case so I use React to build widgets (or if even more complex SPA then Angular). If I'm using a JS framework anyway, then I don't need HTMX. It's just something else to clutter the project and remember to use.
HTMX has its place but with the user expectation for reactivity in the browser I personally find it too limiting.
This is making your life needlessly difficult.
HTMX is just a fancy ajax layer with a little event handling sprinkled on top. You can and should script to your heart content even if you use it, when you need so.
I use js in all most of my HTMX powered pages. Sometimes just a few lines. Sometimes a whole lot. Sometimes vanilla, sometimes alpine. I even have one where I load react for one single page because I want a community widget while the rest of the site is pure HTMX.
You can do whatever you want.
My point is that if you are going to use a JS framework then it will do the same as HTMX and I don't have to remember where to draw boundaries of responsibility.
https://dl.acm.org/doi/pdf/10.1145/3648188.3675127
that means you may be able to express more of your UI needs in HTML, using the traditional REST-ful architecture of the web (HATEOAS, in particular) and reserving JavaScript for the areas where that additional complexity adds the most value.
Depending on your application, this may lead to significant reduction in application complexity:
HTMX is really only about swapping out the elements on the page and pushing updates to the server, which in this case might just be lazy loading the calculator component that contains Alpine attributes and Tailwind elements, and HTMX only if there are elements to swap or you need to save state to the server.
And what happens after the user spent all that time adjusting their order, submits it, and then is told at the very end that some items are out of stock? Do you think they're going to be happy about that?
What if their browser crashes and the order they had built up carefully is lost? Will they bother to try again?
Will you do price calculations properly with a proper decimal library or allow the user to see what IEEE754 floats think '0.1 + 0.2' should be?
Lot of questions come up with the client-only approach.
Stock doesn't matter for my case.
The browser has storage options to handle close and reopens.
Prices in each currency are all in ints (i.e. cents) to avoid float issues.
There are problems to address on either end that you have to be aware of.
It's a simple usecase but nonetheless I was blown away by how trivial HTMX made it! Very cool.
Like 100 lines of code total to get it rendering in a browser with live updates over a web socket.
And it’s fine? htmx allows you to write JavaScript. It’s probably one line, I don’t think everything you can come up with needs to be part of htmx.
It’s not all or nothing.
Evidently you can use Hyperscript for this. Its website <https://hyperscript.org/> demonstrates it with a similar "copy" button.
Don't bother with libraries like this.
This one jumped out to me as an interesting one for a patch release. Changing the default behavior feels like a breaking change, though hopefully there weren't sites expecting an ajax call to not do anything.
The semver docs explicitly address this scenario. If a change in minor update breaks compatibility release a new minor update to revert the change.
Semver is just _indicative_ attempt at describing changes.
If this wasn't true, we wouldn't have lockfiles.
Ie. semver is just approximate attempt at change description that aids/helps development/maintenance but should never be fully trusted.
The only way it could fully work in automated fashion is if the whole program would be written in some formal proof language – then dependency upgrades could be considered as breaking or non breaking. But again, easier and more precise from end user position, not author's position because breaking change in one project can always be non breaking in other if that part is not used/used in more relaxed manner.
It didn’t need to do nothing, it just needed to have no visible effect.
I would be absolutely astonished if this affected no one. It’s very easy to imagine someone having written
htmx.ajax("GET", "/some-tracker-that-returns-nothing-or-json-or-something")
And now your body is clobbered, leaving either nothing behind or a raw JSON response or some such thing. Seriously.Should such a person have used fetch() instead? I dunno, probably; I don’t use htmx.
This is an extremely breaking change.
Either way it sounds like this was a fix to a bug introduced in the last patch so the semver makes more sense here.
thatsthebeautyofit.com in shambles
I'm fine with breaking changes personally. An adherence to maintaining backward compatibility always is what leads to bloat and criticisms of "poor design" from HNers in the future.
Keep it slim, have one way to do things, and avoid the disaster that is js and python today.
sessionStorage wouldn't survive a tab close
i'm not opposed to making the latter an option though
That isn't very common.
> sessionStorage wouldn't survive a tab close
When a tab is restored, the browser typically restores sessionStorage.
> i'm not opposed to making the latter an option though
That isn't what I was getting at. If I'm going to buy into htmx, I want to understand the design. I wondered why this was the default, and why I hadn't seen it mentioned as a security concern.
no strong opinions on session vs local storage, i was trying to make htmx act as much like the browser as possible and the browser caches across tabs
you can disable history on any page by using the hx-history attribute and you can force a server request on every history navigation by setting the htmx.config.historyCacheSize config option to 0:
SessionStorage by default with prominent placement in the docs would be better I think. It would automatically clean up the data from visitors' disk space at appropriate times, whereas the localStorage setting puts it in a place that gets persisted for quite some time.
Thanks for those links, I've read them but it's good for others here to see them.
If a website or application basically has to do the 2024 equivalent of "don't hold it that way", it's the result of a broken development model.
Also curious, why are you arguing so intensely for a “solution” that seems to only be worse and introduces issues as explained, without ever having stated any problem you are trying to solve with the change?
Is it guaranteed to do this? Otherwise, if it just sometimes does it, or different browsers handle it differently/may change in the future, it seems like a recipe for problems.
Chrome does, however, if the “resume where i left off” setting is enabled.
so are you:
I'm an htmx CEO, btw.
I'm hoping there is more innovation in this space with React engineers rediscovering the benefits of server-side rendering and Backend-For-Frontend efforts.
I think the perfect stack involves all 3 paradigms (initial loads, hypermedia loads and data/AJAX loads) used in parts of the application as makes sense.
React 19 has just been released recently with server components and server actions. Worth having a look. It's a very powerful model.
WebAssembly (wasm) already runs in the browser, but now also it is being used to create cross-architecture executables and modules that might (so they say) replace k8s.
The main problem I have with htmx is it requires my backend and frontend to be uncomfortably coupled. I write most of my backends in Go these days, but I've written a lot of Java and PHP in the past. I particularly hate PHP and the model of mixing backend logic and presentation markup. I'm not a fiend when it comes to separation of concerns; I try to keep relevant things together. With that said, constantly bundling markup with actions is annoying. For example, POSTing a comment would require the backend to send back the new comment's HTML, then possibly perform some action like bumping off comments that are too far down.
The other big problem I have with htmx is that it has no good solution for managing state and staying consistent with the backend. I used to work on a site written in PHP that, while not using htmx, used generally the same system of returning HTML from ajax calls. I was working on implementing comment replies, which required not only appending a new comment, but changing some of the markup on the original comment to indicate that it had replies and a button to collapse those replies. The solution I chose for this was to make those changes to the original comment dynamically with raw JS, then append the HTML for the new comment returned by the server. This worked fine, but it was annoying because I had to replicate rendering logic in both JS and PHP. This kind of thing can easily become death by a thousand papercuts as your site grows and you have more and more duplicated rendering code. This problem does not exist in the Vue/React/etc. world.
There is value in keeping all your rendering in one place, even if that place is the server and access to it requires enduring network latency. I understand why someone who uses a language other than JS for backend would enjoy htmx, but I think it's going to bite its users in the ass one day or another when their application becomes too big and rendering logic becomes hard to maintain.
I would say my favorite alternative to htmx for people who want statically rendered pages but don't want to go without niceties like components, JS type checking, reactivity and other things that speed up frontend development and make it more scalable is Inertia.js. It allows you to use a JS frontend framework like Vue or Svelte and the backend of your choice without having to write an API or (god forbid) GraphQL. https://inertiajs.com/
I've also found that petite-vue is great for adding progressive enhancement to otherwise static sites without using a bloated framework. I've used it in several contract projects and it works like a charm. https://github.com/vuejs/petite-vue
https://htmx.org/essays/two-approaches-to-decoupling/
htmx uses Hypermedia As The Engine of Application State:
https://htmx.org/essays/hateoas/
The problems you have had appear to be addressable using techniques outlined here (from least to most complicated):
https://htmx.org/examples/update-other-content/
Of course, there are going to be applications and features that the hypermedia approach are good or not appropriate for, I try to outline those situations here:
https://htmx.org/essays/when-to-use-hypermedia/
I think you could build an excellent comments system using htmx if you wished to.
But I hit walls when I needed more complex stuff. Like, if I want to keep state on the client (e.g., a live calculator or sliders updating a table), Htmx feels clunky. Sending a request to the server every time a user adjusts a slider—yeah, no. React or Svelte is a better fit there. And if you're already using those tools. Htmx starts to feel redundant. Why add more when you've got everything in one place?
Also, not sure about the recent patch release - Changing default behavior in a minor update? Feels risky, even if it's "fixing a bug." Imagine waking up to find your body tag wiped because you updated without reading the changelog, yikes. Makes me think twice about trusting it in production.
Butfor MPAs or projects that lean heavily on server-side rendering, it’s a game-changer. You’re not rebuilding the wheel, just enhancing it. Htmx has a sweet spot—it’s just not always the right tool for every job. Depends what you're building, I guess...
Also, do people just update and yeet their apps into prod without testing it? What happened to test environments? Test suites? Manual QA? Letting it soak? Where did quality control go?
It has limitations (not going to use HTMX to build Google Maps) but handles the 80% of use cases well for little added skillset required.
https://htmx.org/essays/a-real-world-react-to-htmx-port/
how to determine if it is appropriate:
>Nested shadow root
>element is reinitialized via htmx.process()
>Boosted <form> tags
>htmx-powered elements located outside a form, but that refer to a form via the form attribute
>preload, hx-boost, response-targets, ws, head-support, sse
I see... Folks at HTMX are always thriving for a little bit more power of hypertext.
Remember guys this is how S.I.M.P.L.I.C.I.T.Y. looks like.
Fnatics, unleash your downvotes!
I mean it's nice that it's a bit more modern but still.
https://x.com/intercoolerjs/status/1845878585078567084?t=p41...