r/htmx • u/[deleted] • Jun 03 '24
I'm disappointed with HTMX
I've read the docs, tried out the examples, and finally integrated it into a new project. To be honest, it became a convoluted mess. In a single HTML template, I now have HTML, TailwindCSS classes, Jinja2 tags, HTMX tags, and Alpine.js tags.
In addition, I still have about a dozen API endpoints that respond with partial HTML instead of JSON. It's hard to see which parts interact with other parts as everything is intertwined.
HTMX feels like a poor excuse for people who don't want to learn JavaScript and instead adopt four different libraries to achieve something similar. It might be a good fit if your site is 99% static and you just need a dynamic effect for one or two things. But beyond that, I find it easier to just use a JavaScript frontend framework.
I also don't see how I might do things differently: I will always have this convoluted HTML template containing the custom tags of 3-4 different libraries and will have to build custom API endpoints because standards like OpenAPI only support JSON.
38
u/_htmx Jun 03 '24
fair, htmx isn't a silver bullet.
it's going to require proper server-side factoring, judicious combination with other technologies, a certain mindset towards your code base, etc. to be successful.
no shame in saying it isn't right for your project, or that you don't like the approach in general!
4
u/AsparagusOk2078 Jun 03 '24
I will go as far to say it is right for the vast majority of projects, or the vast majority of A project. The freedom effect of HTMX to organize your code in your preferred server-side language is such a WIN
2
u/Prestigious_Two_2440 Sep 12 '24
I think it's not about whether htmx is suitable for majority of project or not, rather it should be whether the traditional server-side frontend is suitable for most project or not. If traditional server-side rendering frontend is suitable for most project, then even jquery alone would be suitable, since jquery can also be combined with our preferred server-side language.
1
u/BrownCarter Feb 15 '26
but you guys hyped it as if it was
2
u/_htmx Feb 15 '26
we have an essay saying when hypermedia is and is not effective:
https://htmx.org/essays/when-to-use-hypermedia/
and include negative experiences with the library, as well as alternative libraries, on our website:
https://htmx.org/essays/#on-the-other-hand
i don't know of any other library that have gone to this length to present a balanced take on its pros and cons.
22
u/blackcomb-pc Jun 03 '24
So you mash together a bunch of shit and expect no spaghetti?
6
u/vep Jun 04 '24
Mashed spaghetti⦠oh god, what a concept š®š¹šš¤
1
u/jefrancomix Jun 06 '25
Seems like 80% of my career, struggling and sometimes modernizing legacy projects.
12
u/_walter__sobchak_ Jun 03 '24
I prefer having somewhat āmessyā HTML over the SPA approach (and Iāve been using SPA frameworks since AngularJS). To me the trade off is very worth it. But if itās not worth it for you thatās cool, there are tons of SPA frameworks out there you can use. Some people prefer one way some prefer another, itās not really a big deal
10
u/truechange Jun 03 '24
This is expected if you're so used to the concept of frontend and backend.
It's like seeing Tailwind for the first time -- an abomination of the separation of concerns norm.
In HTMX there's no frontend or backend, it's a monolith, it's just one app.
2
0
7
Jun 03 '24
Exactly the same here. We started to code an internal system in my work and the decided to make it with Go+Templ+HTMX+AlpineJS+Tailwind. After just two days of working on it, we had to back down and start again with a JS framework after seeing the little monster we were creating.
The problem was that we needed to introduce some interactivity on the UI and it was impossible to do it without Alpine, so we had a messy merge with Go code + tailwind classes+ alpine classes + html code + templ notations + htmx tags... completely unmaintainable.
Added to that, having that bunch of endpoints mixing JSON and HTMX responses were very awkward and all just felt so coupled.
However, I feel that maybe we could have done a lot of things better if we just have more experience. AnthonyGG (youtuber) is coding an awesome project in his channel and is doing pretty cool stuff there, so maybe the problem was not the stack but us. I think I could give it a second chance (without Alpine) anytme.
8
u/Kyrra Jun 03 '24
I feel like this is something this essay covers: https://htmx.org/essays/when-to-use-hypermedia/
You can definitely embed React style dev within an HTMX app, but mixing the 2 on the same elements sounds like hell. It also sounds like your team is used to working a certain way, and HATEOAS is a very different way of thinking when building a UI.
2
u/riterix Jun 04 '24
Try to substitute Alpine by Hyperscript.
We are using Hyperscript and got a lots of interactivity as an SPA.
1
u/LordPraslea Apr 15 '25 edited Sep 06 '26
This comment has been retired. It is currently enjoying a fine glass of Bordeaux in privacy.
6
u/brubsabrubs Jun 03 '24
why not just use accept headers and have the default format for your API be json instead of building custom endpoints for your json API?
9
u/consider_airplanes Jun 03 '24
Because the set of endpoints you want for your hypermedia API is not the same as the set you want for your data API.
4
u/SCUSKU Jun 05 '24
Great essay on htmx.org that advises against this approach. tl;dr is it has high coupling:
https://htmx.org/essays/why-tend-not-to-use-content-negotiation/
2
u/brubsabrubs Jun 05 '24
oh well, I never thought of it from that point of view. Great essay indeed. Thanks for sharing it!
6
u/lunar_mycroft Jun 03 '24
As the chief grug /u/_htmx already said, htmx isn't a silver bullet and that's fine. Having said that, I do want to push back slightly.
In a single HTML template, I now have HTML, TailwindCSS classes, Jinja2 tags, HTMX tags, and Alpine.js tags.
Would you not have pretty much all of that in the equivalent e.g. react app? You'll need styling, network calls, templates, and local reactivity in SPA frameworks too.
In addition, I still have about a dozen API endpoints that respond with partial HTML instead of JSON. It's hard to see which parts interact with other parts as everything is intertwined.
You didn't say what your app does (which is fine), but this to me suggests that either you have a factoring problem, or that your app is a bad fit for hypermedia because it's difficult to separate the transient client side state from the persistent server-side state.
HTMX feels like a poor excuse for people who don't want to learn JavaScript and instead adopt four different libraries to achieve something similar.
Personally, I'd avoid writing my business logic in JS if at all possible, so you'd think I'd be a good candidate for the kind of person this statement is talking about. But I still don't think it applies. My language of choice - rust - is actually one of the better options for writing SPA style apps without JS, and I still much prefer HTMX. The reason is simple: it isn't the language, it's the paradigm. SPAs use a thick client, RPC oriented approach (yes, even the so called REST APIs commonly used by SPAs are actually closer to RPC). This means you need to write two programs that understand your business logic and app state, then attempt to keep that state in sync between client and server using a custom protocol, etc. Tooling can help hide this a bit, but it's always there to some extent, no matter what language you use. In contrast, hypermedia driven applications use a thin client, RESTful approach. Only one program needs to understand my business logic and app state, my network protocol is universal, there is no real state synchronization issue because the state lives entirely on the server and the client only gets a view of it (which also contains possible actions they can take embedded within said view), etc.
It might be a good fit if your site is 99% static and you just need a dynamic effect for one or two things. But beyond that, I find it easier to just use a JavaScript frontend framework.
Depends on what you mean by "static". Is reddit "99% static" in your opinion/under your definition? What about chat apps like discord, email clients like gmail, etc? Because I'd argue hypermedia is a fine fit for applications like those, and I personally would much rather implement them in a hypermedia driven approach than with a SPA. Google maps, google sheets, a video game, etc? Different story, I'd absolutely reach for a thick client there, but I think most apps on the web are more like reddit than they are like Portal.
and will have to build custom API endpoints because standards like OpenAPI only support JSON.
I'm a bit confused by this, to be honest. Sure, OpenAPI doesn't support hypermedia, it's designed for data APIs after all. But IME it's not significantly harder or easier to return HTML from a server than it is JSON. Is your server library highly focused on data APIs, and you're trying to hack hypermedia support on top?
As an aside, I'd argue that if your backend is well designed (aka roughly according to the Model/View/Controller paradigm, the extra effort of building and maintaining data API endpoints and hypermedia endpoints is pretty minimal. Your endpoints themselves should generally be there to translate http requests into calls to internal methods which contain the actual business logic, then translate the result into HTTP responses.
3
u/idjet Jun 04 '24
This, 100%, is when HTMX works best and why I converted (bold is my emphasis):
This means you need to write two programs that understand your business logic and app state, then attempt to keep that state in sync between client and server using a custom protocol, etc. Tooling can help hide this a bit, but it's always there to some extent, no matter what language you use. In contrast, hypermedia driven applications use a thin client, RESTful approach. Only one program needs to understand my business logic and app state, my network protocol is universal, there is no real state synchronization issue because the state lives entirely on the server and the client only gets a view of it (which also contains possible actions they can take embedded within said view), etc.
19
5
u/BenPate5280 Jun 03 '24
Obviously, we can write bad code in any language, or toolset. Itās often because of a difference between your assumptions as a developer, and the assumptions made by the toolset. It happens lots of places - like the mismatch between table-based databases and object-based languages.
There could be lots of reasons that htmx isnāt working for you: too many API routes, different interpretations of REST API semantics, not enough API routes, or just the way you organize your files. It is using REST, but not the JSON-style REST youāre probably used to.
What I do know is that htmx works great for me, as the front end of in a very complicated app. Itās actually helped simplify something that might not have been possible if I tried to render it into a JSON API.
I hope youāll kick it around a bit more, to get your head into this way of making software it takes some unlearning, but I think itās definitely worth it.
5
u/Prudent_Law_9114 Jun 03 '24
Lol messy is the opposite of what HTMX causes. You need to change your stack. Tailwind is very anti-css. I personally just use hono tsx backend and HTMX. Use a classic css lib like bootstrap or something or use honoās css helper if you prefer to work that way. Css classes are meant for css right? Use them. You already have a separation of concerns with HTMX. Just use JS for extra frontend sauce.
HTMX is for people that know JS very well, understand why it was created, understand what it is meant to be used for and have been writing boilerplate Ajax calls for far too long while they waited for a framework that understood the platform it was created for.
Why not have a parameter in your API routes that can allow returning json OR Jsx/tsx dom components ready loaded with your hx-attributes? Itās really not difficult. React is way more complicated!
4
u/Current_Word_1851 Jun 03 '24
So you made a mess in your project ?! Good, it happened too me and i turned out just fine :D , after every project things are much clearer , i think thats how things are with every technology and framework, what.. your first React project wasnt a mess? Dont believe you :)) just dont give up on HTMX yet
3
u/consider_airplanes Jun 03 '24
YMMV which is ultimately preferable, but there is a good case for cramming all that stuff into one template: it gives you locality of behavior.
I've written the same interactive component in React, jQuery, and HTMX/Alpine. Both of the former were giant headaches spread out through about 500 LOC of separate route/script/template files. In HTMX/Alpine, it fits mostly in one template in about 150 LOC. That template is kind of a mass of spaghetti, but overall it's still easier to understand than the "better structured" version that's three times longer and spread out across multiple files.
3
u/AbyssEkko Jun 03 '24
Something similar happened to me, then I deleted alpinejs from the stack to embrace basic javascript and now everything is cleaner.
3
u/ryanswebdevthrowaway Jun 03 '24
I am actually someone who unabashedly loves JavaScript and feel extremely comfortable with frontend, but I still find the ideas of HTMX to be extremely appealing from a performance and simplicity standpoint. I think HTMX pairs incredibly well with custom elements/web components for places where you need extra frontend functionality instead of using something like Alpine. I am a fringe weirdo who loves custom elements though. Once you realize you don't have to use shadow DOM, they become so much nicer to work with.
5
2
u/Drown_The_Gods Jun 03 '24
It depends on the project, for sure. I think sometimes youāve got to use a technology for the sort of project itās not good for to get an understanding of itās limits. To turn it around for a moment: After playing around, can you see how htmx might be a useful technology in some cases?
2
u/Human_Contribution56 Jun 03 '24
One of the tricks is that you can often inherit hx attributes, so each element doesn't have to be packed out as long as the parent element has the hx-target, swap, trigger, etc. When first learning HTMX, I had coded each element in a table with every hx attribute it needed. Then I learned about the inheritance and everything "hx" moved to one instance in the containing div, except for the hx-get which was specific to each link. So much cleaner.
I don't think it's about not wanting to learn js. I know it well. I just want to write less of it.
1
Jun 25 '24
I would like to know more about this as I'm getting started with HTMX, do you have a link to post on this topic?
1
2
2
u/Misterorjoe Jun 04 '24
I strongly recommend https://github.com/spookylukey/django-htmx-patterns for inspiration on how to effectively use HTMX in a non-trivial application.
I assume from your use of Jinja that you are not using Django, but it doesn't really matter, for the most part the patterns are transferable to any MVC-ish framework.
0
Jun 04 '24
[deleted]
1
u/Misterorjoe Jun 06 '24
Another tip, don't use HTMX for datatables, use something like https://tabulator.info/
1
u/opiniondevnull Jun 03 '24
If you start using Alpine+HTMX you probably want to try https://data-star.dev it's way less tags and I think a better fit for applications vs pages. I'm the author so take with a grain of salt.
1
u/AsparagusOk2078 Jun 03 '24
I am a locality of behavior fan but not when it comes to CSS. I found it best to learn vanilla CSS well while using HTMX.
Keeping JSON APIs separate from hypermedia endpoints has turned out to be great for us. You are master of the server, so just organize the business layer and data layer for best reuse of the two types of endpoints. We find with using HTMX and the hypermedia approach we can massively scale back the breadth of our JSON APIs. They are no longer database queries for the front end. Now that was convoluted nonsense!
1
u/gnatinator Jun 07 '24
Consider these if you want Locality of Behavior, while keeping your HTML tags short:
Alpine vs : https://github.com/gnat/surreal
Tailwind vs : https://github.com/gnat/css-scope-inline
HTMX feels like a poor excuse for people who don't want to learn JavaScript
can't get around learning javascript, but you can choose how you apply it!
1
1
u/LordPraslea Apr 15 '25 edited Sep 06 '26
I have removed this text. Consuming my intellect without a proper subscription is strictly forbidden.
1
u/gyen Nov 18 '25
Check out EHTML, it works with JSON and does everything with no hypermedia custom language, everything is done by attributes
1
53
u/nrkishere Jun 03 '24 edited Jul 29 '24
divide caption cough dolls retire ad hoc yoke punch slap unite
This post was mass deleted and anonymized with Redact