Less Htmx Is More

9 days ago (unplannedobsolescence.com)

It is amazing how quickly a simple, traditional, "collection of pages" type website actually works if you don't do annoying things to slow it down. Most websites would be absolutely fine if a) HTTP was used reasonably well to set things like cache headers, and so (as mentioned in the article) and b) if a load of user-irrelevant stuff like tracking and advertising code wasn't thrown in as well. A simple page with standard HTML, passably optimised assets where needed, and only the JS needed for actual functionality, should be almost instant on most modern connections.

  • I believe some of these issues are caused by framework abstractions.

    New developers learn the framework and never learn how HTTP and HTML work.

    Experienced developers have to learn how to punch through the framework to get to these features we get automatically with statically hosted assets.

    • Very likely. I remember reading a while back about developers who thought of rendering things on the server side as novel, which was absolutely wild to someone who was writing web pages before JS was a thing! It's such a shame because HTTP + HTML is actually a very, very simple system to learn with literally decades of hard-won knowledge baked in (particularly HTTP and surrounding standards). People end up inventing incredibly complex solutions to problems that could have been alleviated by reading a few RFCs.

    • Pretty much. I can't tell you how many times I interview these "framework developers" and they cant tell me how a regular HTML form submission works. Boggles my mind.

    • As you can see even the basic documentation is compromised at this point:

      https://unplannedobsolescence.com/blog/behavior-belongs-in-h...

      <button onclick="alert('I was clicked!')">Click me</button>

      ,,You can find HTML attribute equivalents for many of the event handler properties; however, you shouldn't use these — they are considered bad practice. It might seem easy to use an event handler attribute if you are doing something really quick, but they quickly become unmanageable and inefficient.''

      ,,You should never use the HTML event handler attributes — those are outdated, and using them is bad practice.''

      And then proceeds to suggest this:

      <button>Click me</button>

      <script> const btn = document.querySelector("button")

      btn.addEventListener("click", () => { alert('I was clicked!') }) </script>

      After this, next step would be putting javascript to a separate file, and on a slow mobile connection in a random airport with thousands of people using the same wifi, a simple working code gets timeouts.

      20 years ago all I needed to know was this, and it worked great:

      <button onclick="alert('I was clicked!')">Click me</button>

    • I don't believe you can break past "absolute beginner" without learning some HTTP and HTML. Most JS frameworks aren't very good abstractions (which is fine).

      1 reply →

  • > "Like any new tool, especially a tool that got popular as quickly as htmx, there are differing schools of thought on how best to use it."

    If so, it's not because for lack of a written down philosophical framework. See Hypermedia Systems by Carson et al.

    https://hypermedia.systems/

> Like any new tool, especially a tool that got popular as quickly as htmx, there are differing schools of thought on how best to use it. My approach—which I believe necessary to achieve the results described above—requires you to internalize something that htmx certainly hints at, but doesn’t enforce: use plain HTML wherever possible.

That’s the path for ultimate long term functional web pages!

  • Having been out of the web dev game (or at least ‘front end’ as you cool kids are calling it? ;) for a while, I was a little dismayed when I asked an LLM for a web page that did a specific thing. It required Bootstrap and Angular and a bunch of other stuff. Asked it nicely to redo it in plain HTML and JS and the resulting code was simpler and no longer then the original, with no external dependencies.

  • In the pursuit of ultimate long term functional web pages, how does that affect maintainability, e.g. changing requirements? In my mind, the less characters used the less effort it takes to change it, but this might be obsolete thinking wrt AI assisted (or fully written) sites.

    • I agree! As a journalist that codes his own site/blog, I've never took the time to learn anything more complex than good and old HTML and CSS to structure a page, and the short incursions I had in complex system (node, SCSS, frameworks), the returns for the kind of sites I developed was so little I couldn't be bothered to climb the learning curve.

      HTML + CSS + sprinkles of vanilla JS is the perfect recipe for readable, fast, and high resilient web pages.

  • Agreed! TLDR:

    Use plain HTML wherever possible for long term functional web pages!

    • I have made many many web pages over the last 15 years of so that is for just a few months or days. What I do is archive it on way back machine, and if the page works on way back machine then that is my stamp of approval for the page. It can also tell you the page is self contained! It works pretty well with WebGL and event audio playlist. There is NO point of making web dev so complicated just because FANNG company are using the framework. It is designed for they corporate structure. Anyone else should NOT use FANNG based framework!

      For long term web, I stay way from SPA with a long stick.

There are two sides to the argument which I think should be treated separately: a) Is it a good idea overall? and b) is htmx implementation good enough?

a) I think so, yes. I've seen much more spa that have a completely broken page navigation. This approach does not fit all use cases, but if you remember that the whole idea of htmx is that you rely on webserver giving you page updates as opposed to having a thick js app rendering it all the way it makes sense. And yes, js libraries should be wrapped to function properly in many cases, but you would do the same with no react-native components in any react app for example

b) I don't think so. htmx boost functionality is an afterthought and it will always be like this. Compare it with turbo [1] where this is a core feature and the approach is to use turbo together with stimulus.js which gives you automagical component life cycle management. Turbo still has it's pains (my favorite gh issue [2]), but otherwise it works fine

[1]: https://turbo.hotwired.dev/ [2]: https://github.com/hotwired/turbo/issues/37

  • htmx boost functionality is an afterthought in the main use case it is marketed for (turning a traditional MPA into something that feels like a SPA), but it's actually super useful for the normal htmx use case of fetching partial updates and swapping them into a page.

    If you do something like <a href=/foo hx-get=/foo hx-target="#foo">XYZ</a> the intention is that it should work with or without JavaScript or htmx available. But the problem is that if you do Ctrl-click or Cmd-click, htmx swallows the Ctrl/Cmd key and opens the link in the same tab instead of in a new tab!

    But if you do <a href=/foo hx-boost=true hx-target="#foo">XYZ</a> everything works as expected–left-click does the swap in the current tab as expected, Ctrl/Cmd-click opens in a new tab, etc. etc.

    Also another point–you are comparing htmx's boost, one feature out of many, to the entirety of Turbo? That seems like apples and oranges.

  • Would like to second the turbo rec. I've had good results with it for nontrivial use cases. Would like to hear from people if they have different experiences. Also, praying that everything gets cached first load and hand waving that view transitions will eventually work is not a position I want to hear from an engineer in a commercial context. Really happy to see the author bring more attention to how good vanilla web technologies have gotten though.

> Updates that users would not expect to see on a refresh (or a new page load)

I always hated this idea. As a user, a refresh indicates that something is happening and it's abundantly clear when something is wrong. People don't always handle errors and in all fairness they shouldn't - a developer has no way of knowing what custom stuff I have on my browser, whether I'm using any blockers or pi-holes or whatever and they should not know. Simple navigation, refreshes and server side rendering is something which worked great, the web was fast and could run on anything with a graphical output. These days a single page eats up 150+ mb while it loads. All that so the page doesn't "refresh".

  • It's not that smooth looking if a refresh takes 500 milliseconds. Then it flickers.

    • 500ms means a slow connection, high latency or significant bloat.

      Optimising the page and using a CDN can help alot.

      It is a shame HTML doesn't have rel="swap" in links to "swap" in a new page.

  • > a developer has no way of knowing what custom stuff I have on my browser, whether I'm using any blockers or pi-holes or whatever

    That's a feature.

    > and they should not know.

    Yes, a fetch failing, DOM being updated is standard web behavior, interns handle that.

> “You didn’t solve anything! Doing validation is complex and you just magic wanded it away by designing a perfect interface for it.” Yes. Exactly. That is what interfaces are supposed to do. Better semantics make it possible for the programmer to describe what the element does, and for someone else to take care of the details for them.

Gosh I couldn't agree more, what a wonderfully succinct way to communicate what I spend a ridiculous amount of time trying to explain to my colleagues when designing programs!

[EDIT]: I just realized I had read this on one of the linked articles https://unplannedobsolescence.com/blog/behavior-belongs-in-h...

Anyone replace some HTMX usage with the View Transition API that's now in Chrome and Safari? https://developer.chrome.com/docs/web-platform/view-transiti...

This looks appealing where it makes sense (page transitions, table sorting/pagination) and if Firefox gets around to adding it.

  • I really want to like the transitions API but I've been frustrated by it multiple times.

    It feels like they wanted to build page animations similar to what Windows Phone had 15 years ago. That would be great, Windows Phone transition were surprisingly nice.

    It just doesn't work on the web though, its an after thought. Animations on windows phone only worked because it was designed into the UI library and rendering engine from the beginning.

  • I really hope this won't become the new craze. The examples triggers all my irritation triggers. I couldn't use a website like that.

I have used htmx just a little bit; but I have found htmx + solid.js for some small reactive components to be ... very, very pleasant and very much else of what this blog post says to be accurate.

I've written a lot more html than I have in the past and it just ... feels good? html has upgraded quite a bit in the last decades since I learned it.

>Triptych—the HTML proposals that Carson and I are working on—would render htmx obsolete for the type of website I describe here.

Which we discussed here [1], is still no where near getting even looked at. Browser maker are not interested in anything HTMX. Vast majority of browser developers still want JS driven web apps, served with AVIF image.

[1] https://news.ycombinator.com/item?id=42615646

How do you get flicker free navigation using htmx without using hx-swap or boost? I see that this article refers to https://unplannedobsolescence.com which has a header that remains the same, but it also doesn't change. Normally a header will do some type of change, e.g. showing which menu item is currently selected. That's when the flickering starts, in my experience.

> The idea here is that the website still has a sound URL structure, which is managed by the core browser functionality, while interactivity is carefully layered on top, with targeted updates.

It’s a long time since I have to work with websites. JQuery was the hot stuff back then. But we didn’t used it. It was all HTML and a Java backend. This sentence implies that right now basic stuff isn’t managed by the browser (but by React, Vue and so on?) which seems to be simply wrong.

  •     > This sentence implies that right now basic stuff isn’t managed by the browser (but by React, Vue and so on?) which seems to be simply wrong.
    

    That's exactly what's happened. A React SPA .html is just an empty shell. A Next.js app renders HTML using React on the first load and then becomes an SPA on the client.

Yes if you click a regular link in a modern browser on a noJS or lowJS reasonable size page it is darn fast.

And the predictability is a boon. Open in new tab, back button etc.

While I agree that full page refreshes probably shouldn't use HTMX, I'll also claim that it's pretty rare that you would do a full page refresh. Almost every website I create has context that is present on every single page. Typically the branding at the top and the site map at the bottom does not change and hence there are no full refreshes.

I like Hotwire/Turbo more than HTMX because of its core philosophy: start by building a fully functional page without any JavaScript, and then layer in enhancements only as needed. That approach has stayed consistent for years and feels really straightforward to work with.

  • This is exactly how I use htmx. Is there an expectation that you use htmx differently?

Yea, in my opinion, hx-swap or turbolinks is a bit of an antipattern. Seems to me you get worst of both worlds:

- something that kinda looks like full reload

- but with all problems of client side routing

- and without preserving the DOM state like SPA would

- and you don't get the immediate response that is the main reason to build the SPA in the first place

In fact, it's often even slower than native navigation, because native navigation can start processing the stream during download and there's overhead with pre and post processing of the response in the boosted link version. Try to profile GitHub links to see what I'm talking about, opening a link in new tab can be 2x faster than clicking in the same tab.

I thought HTMX is useful mostly for SPA style apps. If you want a website with individual pages you can mostly use HTML and a bit of vanilla JS for the stuff that needs to be dynamically updated.

  • It's the other way around. HTMX is not suitable for client-side scripting heavy app like SPA. It's more for "traditional" AJAX-style web app.

  • htmx gets rid of the "bit of vanilla js" and replaces it with "a couple very, very short tags" and then the backend returns partial html, making the experience seamless.

    It's written in Javascript, so yes, some vanilla JS can do the same thing; but this library makes that experience easier for the masses, and likely well-tested to the point where more trust can be given to it to be correct.

> In my opinion, most websites should be using htmx

In my opinion, in five years no one uses htmx, but another shiny toy. Hence, how about not starting to use it at all?

  • Hi, author here. The full quote is: "In my opinion, most websites should be using htmx for either:", and then I list two cases where I think htmx is appropriate.

    In context, it's clear that I'm not saying "everyone should use htmx," but rather "if you are using htmx, here is how I recommend you do it."

    As for the shiny object concern, I have a talk (which you can also find on this blog) called "Building the Hundred-Year Web Service", that dives into that question.

  • This applies to every single web framework/library, so I guess your point is that nobody should start making web things?

    • It kind of is - although, with a twist.

      I think most things done currently with the frontend "frameworks", could be achieved with standard HTML5+JS, without any "build steps" or other bloat involved.

      This said, there is a case for building on a commonly used mature platform, such as React, to speed up the development cycle and in order not inventing the wheel again.

      1 reply →

  • I don't share the opinion you've quoted there, but neither do I share yours. Hmtx isn't actually a shiny new toy, it's just a rebrand of intercoolerjs - and I found out about that one in 2014.

    That makes the time since it's inception to date longer then the time between initial react release and initial intercoolerjs release

> In practice, this is virtually impossible to get right

Somehow every other JS frontend framework manages to hook into the History API just fine?

  • The amount of times when I've clicked a link, hit the back button, nothing happens, I hit the back button again and I go 2 steps back in history...

  • The way I read it is that there are frustrating edge cases that (at least the author) has run into, regularly, that would imply it's ... more difficult to custom handle that than to just let the browser do it.

  • What? They all butcher it. On a weekly basis I make the the mistake of clicking some link to a site and find I can't hit the back button to escape. Maybe this is technically the site developers' fault, not the library devs, but it's a lousy experience for users.

  • They do, but mostly they make this work by recreating the entire frontend ecosystem within that framework. Mix-and-match a history-aware JS library from outside the framework's ecosystem, and you may find it's less robust than you expect.

While I get the emotional appeal, I still don't understand the use-case for htmx. If you're making a completely static page, you just use HTML. If you're making a dynamic page, then you want to push as much logic to the client as possible because far more users are latency-limited than compute-limited (compare [1] vs [2]), so you use normal frontend technologies. Mixing htmx and traditional frontend tech seems like it'd result in extra unnecessary complexity. What's the target audience?

Edit: "Normal/traditional frontend" here means both vanilla (HTML+JS+CSS) and the most popular frameworks (React, Angular, Vue, Next).

[1] https://danluu.com/slow-device/

[2] https://danluu.com/web-bloat/

  • You should read the htmx “book” (https://hypermedia.systems/ ) where the use case is clearly explained. It advocates for using htmx to enhance a page with more interactivity by extending html semantics and behaviours a bit (thus requiring minimum effort and learning curve) and move to more heavyweight client-side front end stuff (react and friends) if more interactivity or complex behaviours are needed.

    You can whip up a simple html form and spruce it up with htmx so it feels “modern” to current users, with little effort and changes and importantly without having to learn the insanity that are modern front end stacks. Not only curmudgeons from the 90s like me benefit from this!

  • I agree with the author of the article in that it's often best to do as much as possible in plain-old HTML.

    When an interactive "widget" is needed, I try to simply embed that in one HTML page, and avoid to make the whole app an single page application (SPA).

    SPAs are problematic because you need to manage state twice: in the BE and FE. You also may want a spec'ed API (with client library generation would be AWESOME: GraphQL and OpenAPIv3 have that and it helps a lot).

    > so you use normal frontend technologies

    This is the problem. "Normal" means React/Vue/Angular these days and they are all shit IMHO. This is partly because JS is a rampification and TS fix only what could be fixed by _adding_ to the language (since it's a superset). So TS is not a fix.

    I had great success with Elm on the frontend. It's not normal by any norm. Probably less popular than HTMX. But it helps to build really solid web apps and all devs that use it become FP-superstars in a month.

    Tools like ReasonML/ReScript and PureScript may also have these benefits.

    • > SPAs are problematic because you need to manage state twice: in the BE and FE. You also may want a spec'ed API (with client library generation would be AWESOME: GraphQL and OpenAPIv3 have that and it helps a lot).

      OK, this helps explain some of the reasoning.

      Unfortunately, that means that the tradeoff is that you're optimizing for user experience instead of developer experience - htmx is much easier for the developer, but worse for the user because of higher latency for all actions. I don't see how you can get around this if your paradigm is you do all of your computation on the server - and if you mix client- and server-side computation, then you're adding back in complexity that you explicitly wanted to get away from by using htmx.

      > "Normal" means React/Vue/Angular these days

      I didn't mean (just) that. I included vanilla webtech in my definition of "normal" - I guess I should have clarified in my initial comment (I just meant to exclude really exotic, if useful, things like Elm). Does that change how you would respond to it?

      12 replies →

  • I use it to get some interactivity without reloading that would have to be Ajax anyways. If you have a form inline, you can’t do a lot client side if the server doesn’t work, so using htmx is fine.

  • > "If you're making a dynamic page, then you want to push as much logic to the client as possible because far more users are latency-limited than compute-limited"

    That's an assertion I don't agree with.

    Data still needs to come from or go to the server, whether you do it in a snippet of HTML or with an API call.

    In either case, latency is there.

    • > That's an assertion I don't agree with.

      The part about users being more latency-limited than compute-limited, or wanting to push as much to the browser as possible?

      The former is somewhat hard to quantify, but most engineers building interactive applications (or distributed systems, of which interactive client-server webapps are a special case) have far more trouble with latency than compute.

      The latter is definitely true.

      > Data still needs to come from or go to the server, whether you do it in a snippet of HTML or with an API call. ... In either case, latency is there.

      This is definitely incorrect.

      Consider the very common case of fetching some data from the server and then filtering it. In many, many cases, the filtering can be done client-side. If you do that with an interactive frontend, then it's nearly instant, and there's no additional fetch to the server. If you shell out to the server, then you pay the latency penalty, and incur a fetch.

      "In either case, latency is there." is just factually wrong.

  • Yeah I don't get the irrationality either, especially the dogmatic "hypertext" angle. I mean you can see me pontificating about SGML as the original complement to the HTML vocabulary bringing text macros and other authoring affordances, but that is strictly for documents and their authors. If you want to target web apps and require JS anyway, I don't see the necessity for markup and template languages; you have already a much more powerful programming language in the mix. Any ad-hoc and inessential combination of markup templating and JS is going to be redesigned by the next generation of web devs anyway because of the domain's cyclic nature ie. the desire to carve out know-how niches, low retention rate in webdev staff, many from-scratch relaunches, ..,

  • > If you're making a dynamic page, then you want to push as much logic to the client as possible because far more users are latency-limited than compute-limited

    This implies you value optimization over other concerns, will do ssr & rehydration, etc.

    • I work with user in far location, bad internet signal, and terrible low-end androids.

      Htmx has been the best performant of all my tries before.

      HTML is fast. (also, I use svg everywhere I can)

      2 replies →

  • I reach for HTMX when (a) its a project where I have the power to make that decision and (b) I need to render state that lives on the server.

    My main issue with SPAs, and client rendering in general, has always been the attempt to client render state that is persisted elsewhere.

    There are certain pieces of state that really do live on the client, and for that client rendering is great. A vast majority of cases involve state that is persisted somewhere on the server though, and in those cases its needlessly complex to ship both the state and an entire rendering engine to the browser.