Debian Codegraph @

www/src/content/essays/htmx-sucks.md

raw symbols SCIP
1 ---
2 title: "htmx sucks"
3 description: "This article provides a critical analysis of htmx, a web development library, explaining why the author believes it represents a problematic approach to modern web development due to its outdated coding practices, lack of build tools, absence of TypeScript support, and reliance on HTML-based architecture, while also questioning the professionalism of its creator."
4 created: 2024-02-01
5 modified: 2024-04-01
6 authors: ["Carson Gross"]
7 tags: ["counterpoints"]
8 ---
9
10 I have been following [htmx](https://htmx.org) for a while now. I thought it was a somewhat funny/cringey meme
11 and that it served as some light comic relief from the real work being done in web development, things like
12 [React Server Components](https://react.dev/reference/react/use-server), [Svelte Runes](https://svelte.dev/blog/runes)
13 and [Signals](https://www.solidjs.com/tutorial/introduction_signals) that are actually pushing the state of the art
14 forward.
15
16 Unfortunately at some point [in the middle of 2023](https://star-history.com/#bigskysoftware/htmx&Date)
17 people began to actually take htmx seriously
18 for [some](https://www.youtube.com/watch?v=zjHHIqI9lUY) [reason](https://www.youtube.com/watch?v=r-GSGH2RxJs).
19 This is an extremely alarming turn of events that has me deeply concerned for the future of web development.
20
21 And I'm not alone in my alarm: you can read an excellent [dressing down of htmx here](https://archive.is/rQrl7):
22
23 > Basically they put their ignorance on full display, then attribute all sorts of unfounded merits to whatever they’ve
24 > done hoping that everyone else pats them on the back for it.
25
26 So true. So, so true.
27
28 Unfortunately, the language in that excellent medium post is academic and, without a solid grasp of theoretical HTML,
29 many of the more important points in it will go over a typical web developers head.
30
31 So, in this article, I will attempt to present, in plain language for the layman web developer,
32 why [htmx sucks](/essays/htmx-sucks).
33
34 ## The Code Is Crap
35
36 First of all, consider the code for htmx.
37
38 [Look at this garbage.](https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js)
39
40 They use `var` all over the place, almost no modern JavaScript features (hello, htmx people, have you heard of
41 [Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)?), they pollute the `window` name
42 space, and on and on and on.
43
44 Worst of all, it's just one big ball of JavaScript! One file! It isn't decomposed at all. If this person
45 took one of my [classes at MSU](https://www.cs.montana.edu/directory/2256398/carson-gross) I would fail them based
46 solely on this complete misunderstanding
47 of [Separation of Concerns](https://en.wikipedia.org/wiki/Separation_of_concerns),
48 something any freshman in computer science should be able to grasp.
49
50 Good software starts with clean code, and this code is filthy.
51
52 ## No Build Tools
53
54 The next red flag is the lack of a build step. Not only does htmx not have a traditional build step, thereby depriving
55 themselves of the [benefits](https://vitejs.dev/guide/why.html) that the rest of the JavaScript community
56 enjoys, but they [actively brag](/essays/no-build-step) about it!
57
58 And it gets worse.
59
60 If you look closely, even though they claim to not have a build step, they [_actually
61 do_](https://github.com/bigskysoftware/htmx/blob/bedee219329117fff8d58e33678d82f7c34b08b5/package.json#L30)
62 have a build step, it's just an ad hoc set of bash scripts they wrote themselves.
63
64 Ridiculous _and_ dishonest. Shameful.
65
66 ## No Typescript
67
68 Despite the [obvious benefits](https://blog.logrocket.com/understanding-typescripts-benefits-pitfalls/) of
69 [TypeScript](https://www.typescriptlang.org/) for a project like htmx, the authors have stubbornly resisted using it.
70 Part of this is their irrational opposition to a build step (which they actually have, btw!) but part of it is a
71 ridiculous
72 commitment to "shipping debuggable source code". Of course, as any JavaScript developer who isn't a complete idiot
73 knows,
74 TypeScript supports [Source Maps](https://www.typescriptlang.org/tsconfig#sourceMap) that make it perfectly debuggable.
75 Despite this fact, the authors continue to
76 insist on using an antiquated version of JavaScript for development.
77
78 In a tacit admission that they screwed up, they are now belatedly adding [JSDoc](https://jsdoc.app/) annotations
79 to their codebase (I use the word loosely here). All this to make up for the fact that they didn't do the obvious,
80 correct thing initially and simply write the whole project in modern, modular TypeScript.
81
82 The only good news here is that at least they have a
83 halfway-decent [test suite](https://github.com/bigskysoftware/htmx/blob/master/test/index.html), and given the state of
84 the codebase, they
85 better damned well!
86
87 ## Antiquated Technology
88
89 OK, that covers the major (but by no means all!) issues with the htmx codebase itself. Let's move on to more general
90 issues with htmx.
91
92 The first glaring issue is something the authors, again, brag about: it uses [hypermedia](https://hypermedia.systems).
93 Really
94 this is just a pretentious way of saying "it uses HTML", I don't know why they insist on using a different and confusing
95 term for it, but whatever.
96
97 OK, well, if you haven't noticed, HTML is over thirty years old now. It's ancient. And, moreover, we have lots of
98 experience with the approach these guys are recommending. It's not like htmx is doing anything
99 new: [intercooler.js](https://intercoolerjs.org),
100 [PJax](https://github.com/defunkt/jquery-pjax) and [Unpoly](https://unpoly.com/) (way better than htmx, btw) have been
101 around literally _forever_.
102
103 Even before that, we had [`jquery.load()`](https://api.jquery.com/load/#load-url-data-complete).
104
105 Look at this jQuery code from 2008:
106
107 ```js
108 $("#result").load("ajax/test.html");
109 ```
110
111 And now look at the super innovative stuff the htmx folks give us:
112
113 ```html
114
115 <button hx-get="/ajax/test.html"
116 hx-target="#result">
117 Load
118 </button>
119 ```
120
121 Wow. Amazing.
122
123 It would be funny if it weren't so infuriating.
124
125 ## No Components
126
127 The next reason to consider not using htmx is that there aren't any components available for it. If you go with
128 react you get things like [MUI](https://mui.com/), [NextUI](https://nextui.org/) & [Chakra](https://chakra-ui.com/).
129
130 With htmx, you get... nothing. You have to figure out what components you want to use and then how to integrate them
131 with htmx using events and so forth.
132
133 Do you really want to spend time figuring out how things like [lit](https://lit.dev/) work and then _also_ how to
134 integrate them with htmx? That doesn't make any sense. Far better to go with a front end library with integrated,
135 off-the-shelf components you can just use without any fuss.
136
137 ## No Front-End/Back-End Split
138
139 Another major reason to avoid htmx is that it eliminates the split between the Back-End & Front-End teams. They even
140 have a page with a team [bragging about it as a virtue](/essays/a-real-world-react-to-htmx-port) when their company (
141 foolishly)
142 moved from React to htmx.
143
144 The Front-End/Back-End split has been extremely successful for many companies, allowing the Front-End engineers
145 to focus on building a good user experience, and the Back-End engineers to focus on getting the data access layer
146 right.
147
148 Yes, there are at times some difficulties in coordinating between the two teams, with Back-End engineers complaining
149 that
150 Front-End engineers change their requirements too frequently and Front-End engineers complaining that Back-End engineers
151 move too slowly. But we have technologies like [GraphQL](https://graphql.org/)
152 and [RSC](https://react.dev/reference/react/use-server) to
153 help with that, it's a solved problem at this point within the
154 existing [standard web application model](https://macwright.com/2020/10/28/if-not-spas.html).
155
156 The Front-End/Back-End split has proven a very good organizational model for companies, particularly as they scale their
157 development
158 team, and abandoning it for "Full Stack" (so called) development is risky and, frankly, foolish.
159
160 ## Back-End Engineers Make Garbage UIs
161
162 Leaving aside if the Front-End/Back-End split is good or not, we can definitively say that Back-End engineers make
163 garbage user interfaces.
164
165 Just look at [the htmx website](https://htmx.org). You've got inline styles, tables, a bunch of image tags
166 didn't have `alt` descriptions forever. Just a dogs breakfast of bad HTML, from people who are trying to tell us
167 to use HTML!
168
169 You should leave your user interfaces in the hands of people who understand how to properly build them, and those
170 people are, today, mostly Front-End SPA developers.
171
172 ## XSS Vulnerabilities
173
174 Getting back to a more technical reason why you shouldn't use htmx, it opens you up to a class of security issues called
175 [Cross-Site Scripting attacks](https://owasp.org/www-community/attacks/xss/), abbreviated "XSS".
176
177 The problem here is fundamental to the design of htmx: it enables & and even encourages you to put *behavior* in your
178 markup. Once
179 again we see a clear violation of [Separation of Concerns](https://en.wikipedia.org/wiki/Separation_of_concerns).
180 We've known for ages in web development that you should separate your markup, styling and behavior into HTML, CSS &
181 JavaScript files respectively.
182
183 By violating this obvious and well known truth htmx makes you vulnerable to other people injecting behavior into your
184 web application if you
185 don't [sanitize your HTML](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html)
186 properly.
187
188 Sometimes the htmx author will make a smart-alec comment like "Well, how do you feel about the
189 [href](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href) attribute?", but that's different, obviously.
190
191 ## No Jobs
192
193 Another practical reason not to use htmx is that there are, rounding off, zero htmx jobs.
194
195 I just did a search for htmx jobs on indeed and found a grand total of two: one at Microsoft and one at Oak Ridge
196 National Laboratory.
197
198 A search for "react", on the other hand, gives 13,758 jobs.
199
200 Seriously, developer, which of these two technologies do you want to hitch your career to?
201
202 ## No One To Hire
203
204 The flip side of the above problem is that, if you are a company, there are, rounding off, zero htmx developers.
205
206 Everyone goes to bootcamps and learns React. If you want to have a large potential employee pool (maybe your company
207 has high turnover for some reason, maybe you want to keep employee wages down, maybe a small team of full stack
208 engineers
209 would get in the way of your kingdom building) it makes a ton more sense to go with The Big Dog in front end
210 development.
211
212 Today, that dog is React.
213
214 ## Duplicating (Or More!) Your APIs
215
216 Getting back to the more technical side of things, if you adopt htmx and you want to _also_ have a mobile app or an
217 API for 3rd parties to use, you will need to create that API entirely separately from your web application's end points.
218
219 Here, again, we find that, incredibly, the [htmx people brag about this fact](/essays/splitting-your-apis), completely
220 ignoring the duplication of work involved here.
221
222 It makes far more sense to have a single API maintained by a single, Back-End team that can flexibly serve all your
223 needs.
224
225 This is obvious and, frankly, not worth even arguing about.
226
227 ## It Won't Scale
228
229 Another technical issue with htmx is that it just won't scale. It may work for small applications, but as applications
230 get larger the htmx model breaks down and becomes a mess. The component model of React and other front-end tools keeps
231 everything compartmentalized and testable. This makes it much easier to keep large codebases clean.
232
233 As an example, consider [GitHub](https://github.com/), which started out using technology a lot like htmx. It has
234 recently started adopting React and is now much more stable than it was previously. They would have been better off
235 if they had just started with React and built the whole thing in a modern, component-based way, but at least they
236 are making the right move now. Better late than never.
237
238 ## The Creator Is Unhinged
239
240 Finally, and maybe the most important reason not to use htmx: the creator is obviously unhinged.
241
242 Just look at the [twitter feed](https://twitter.com/htmx_org): unprofessional, childish, intentionally provocative.
243
244 Or consider the fact that he
245 posts [essays he](/essays/is-htmx-another-javascript-framework)) [doesn't agree with](/essays/htmx-sucks) to
246 his own site.
247
248 The essays tab [has a section for memes](https://htmx.org/essays/#memes), most of which are cringe-worthy and all
249 of which have no business being on a website of a front end library that expects to be taken seriously.
250
251 Apparently he allows [anyone to be the CEO of htmx](https://htmx.ceo) and make one of those super-cringey
252 job announcements on LinkedIn.
253
254 Wanton buffoonery.
255
256 When you pick a front-end library you are, to an extent, picking the author of that library as a co-worker. Do you
257 really want to work this guy? I certainly don't.
258
259 ## Conclusion
260
261 I hope this has convinced you that choosing htmx & hypermedia for your web application is
262 an [exceptionally bad idea](https://www.reddit.com/r/ProgrammerHumor/comments/zmyug8/edsger_dijkstra_math_and_memes/)
263 that could only
264 have originated in [Montana](https://bigsky.software). Don't listen to the fanboys and fangirls with their "It's so
265 over",
266 "We're so back" nonsense, CEO profiles and childish memes.
267
268 Software, and especially Front-End software is serious business and needs to be treated with the same gravity as things
269 like law & politics, two other extremely serious and productive activities. We should support libraries that focus on
270 innovation & sophistication, not broken, backwards-looking libraries whose creator spends most of his time posting
271 ridiculous things on twitter.
272
273 It's just common sense: htmx sucks.