One of the happiest days of coding in the last 10 years for me happened in September last year when I added htmx to an internal self serve web app I develop for our company. With the addition of maybe 5 htmx attributes I was able to delete about 500 lines of client side JS.
The app is now chock full of htmx interactions and has very little client side JS for the size of the app and it’s a joy to work on.
Without htmx I would not be able to turn around features as quickly as I do for the wider team so thank you, thank you, thank you.
I’ve been in web dev for 20 years and this feels like what we should have made all along.
The one area I would like to see some development is the file upload experience, I’ve had to do something a bit weird to get htmx and dropzone playing nice.
You deleted 500 lines of JS and added 44KB of (minified) HTMX. Better use HTMZ, which is only 166 bytes (sic!) and provides most of the interactivity: https://leanrada.com/htmz/
It's both. All the JS code has to be parsed and interpreted by web browser, which is affecting especially low end smartphones. Better use plain HTML and CSS whenever possible, see e.g. PHOOOS: https://github.com/niutech/phooos (demo: https://kodus.pl)
It was all normal JS code to handle a complicated form we have on a customer facing portal page. By moving to htmx I was able to rely on the server side to handle basically everything with only a small addition of code to what it was already doing.
I'm qurious what that code was doing that could be just moved to the backend. Usually forms have some validation for a better experience with the final validation on the server. Did you get rid of that and just show an error if the submission failed?
Near enough yes but it was a nice helpful error message with the form fully populated as they left it - as far as it looks the user it’s client side validation as the service responds with just the correct html for the form and htmx swaps out the chunk of html.
Its like old school for validation back in the CodeIgniter days.
Most likely that code already existed server-side and was duplicated client-side. It's what usually happens since frontend code can't enforce invariants.
Frontend code can be easily bypassed or changed so you can't trust it to keep the state of your application in good condition. Nothing prevents me from picking the same username as someone else if there is no server-side code stopping it. Nothing prevents me from replying to a deleted comment if I don't check with the server.
That means that any validation that you do client-side you need to repeat server-side. Any business logic that you have client-side you also need to repeat server-side.
this isn't much of a feature upgrade, but we took the opportunity to clean up a few things and drop IE support, which will help us slim down the library over time
hopefully it's an easy upgrade for most htmx users, upgrade guide is here:
As someone that has long since soured on frontend things despite having tried everything from the start - mootools, jQuery, backbone.js, SproutCore, Ember, React, Vue, etc.
I genuinely think htmx is the only one I have liked even after I built something substantial in it.
To me that is big, to be able to walk away from a significant amount of time with something and say "yeah! I want to use that again!" instead of some variant of "it's the least bad option" is both rare and cherished so thanks for all the hard work.
Not a question, but I just wanted to say that HTMX is a joy to work. I’m using it in production to slowly replace VueJS wherever full SPA interactions aren’t needed, and it has made development so much simpler. HTMX is such a breath of fresh air from the over-engineered jenga tower that web dev has evolved into over the past decade.
Not really. We were lucky that we used a hybrid multi-page architecture that makes the transition easy to manage. HTMX and VueJS are being used on different views with different routes/endpoints, so we can re-write any VueJS-based views one at a time.
This architecture was chosen partly because I am a boomer who remembers when websites were HTML files uploaded via FTP and couldn't understand why we shouldn't just return HTML for pages that didn't need app-style functionality, partly because we wanted something easy to manage with a small number of devs (HTML+vanilla js shines here), and partly because SPAs were new-ish when we first began development and the ecosystem was very immature and a long way from coalescing around a single winner (as it has now with React).
So in this case, HTMX is used with HTML templates and ordinary routing, while VueJS is isolated to single purpose SPA-style views with their own endpoints (for example, WebRTC video). And I suspect that we will even be able to eliminate the Vue-based pages altogether with a combination of HTMX and vanilla js if we want to, with how good vanilla js has gotten.
Are there any efforts to push functionality like this into the HTML standard? It would be nice if htmx eventually became unnecessary as browsers implemented it, and the work you're doing with proving it out in the wild seems like a crucial part of that.
Do you also plan on talking with the Mozilla people? And with Apple? Or will this be a kind of big daddy Google knows what's best for you, ads included?
i have told my chrome team contacts about bugs in other browsers (e.g. safari not properly updating completion results when datalist elements are replaced asynchronously) and they have communicated these issues to those teams and gotten them fixed
if anyone reading this from other browser teams is interested in getting in contact w/me they can email me at carson at bigsky dot software
No question but I wanted to say, I was pulling my hair out trying to figure out which js framework was less of an overkill, and finding htmx was pure joy
Have you considered replacing xhr with fetch? I believe it would allow htmx to be used in even more places. Fetch can be hijacked so returning data to the htmx framework isn't limited to the network. You could "run" a server in the browser or have a native app render HTML as well.
Perhaps, there's already a good way to hijack xhr that I'm unaware of too.
yeah, looked at it, unfortunately fetch() and xhr have a non-intersecting set of features (in particular, upload progress for xhr) so we decided not to touch it
i may restructure the internals to allow for mocking out responses using events, it comes up, especially w/ extensions
Hey Carson! I'm using HTMX on quite a number of internal tools. It's completely revolutioned the way we've done things, especially coupled with Django. Extremely grateful for your work - you're a net positive for humanity.
We are building an enterprise application that manages (create, update data) and interacts with (read, display, enable user to browse via linked entities) a large-scale knowledge graph. In some views we have live updates from the server with SSEs (alerts, logs, etc.). Everything is rendered server side with Go + stdlib templates, Material Design Bootstrap for CSS, and HTMX for all the in interactive bits like fetching and rendering an entity's properties panel, enabling add/edit for entity or edge properties, and so on. Search updates results with HTMX. Entity/property edits are done with HTMX "panels".
The entire experience using Go + Fiber (gofiber.io) + templates + HTMX (htmx.org) is fantastic. This approach has allowed us to create a beautiful modern application that's highly performant, interactive in all the places you'd expect, and simple code, deps, devops, etc.
We use the alpinejs for when we choose not to round trip the server (like data validators, for example) and for cases when we need to do some client side JSON work. Mostly htmx handles what we need. You could also consider it’s client-side template rendering extension, as needed.
Oddly specific. Why implementing "forEach" and "toArray" instead of using the functions from Array.prototype? [1] I can see `Array.from` used elsewhere on the code.
As for slimming down over time, HTMX 1.0 was 26KB minified, now version 2.0 is 48KB minified. Why has it blown up by 184%, when it dropped IE support? Why don't keep it lightweight? Compare it with e.g. Petite Vue, which is 16KB minified.
i think that the better web components support blew is up a little. there is a reasonable amount of fat we can cut around IE support that is still in there, planning on doing so over the next few months & slowly
17ms over emerging 4G (and hopefully cached forever after that) doesn't freak me out too much
It's not only about bandwidth, but JS code has to be parsed and executed, which takes CPU time, which is especially affecting low end mobile devices. Compare HTMX with e.g. Ajaxial, which is only 5KB minified: https://ajaxial.unmodernweb.com
ah, yeah, i don't know what to tell you, i've gone through the code base a bunch and there isn't much i feel like i can take out that would make much of a difference without a major step back in functionality: history support is a big one, input gathering has gotten more complex as i behave the way forms in HTML actually work, i have a lot of events that i fire, there's the queuing behavior of requests, etc.
my understanding from the browser engineers is that javascript files are compiled and kept in a cache for the browser, and i never see compilation or execution times in htmx profiles unless someone is processing a ton of htmx attributes (1000+ row tables w/ loads of hx-* attributes per row) which is an orthogonal problem
end of the day i don't think grinding out another few K on the minified source is gonna make a big diff, although we do plan on doing things like moving to modern closures (i assume gzip nukes most of that advantage, idk)
i think a minimal preact-like htmx might be interesting, not as minimal as htmz, but something close. might be worth looking at if you are interested, the concept isn't hard and w/ different design decisions you could prob keep it really small
As long as hx-boost is in core, it would make more sense to have head support in core? It's difficult to really leverage hx-boost without being able to manage the head in responses.
HTMX is like a glimpse into the road not taken, where HTML is the main language of the web instead of JS. Sometimes the grass really is greener on the other side, and I hope as an industry we make the switch.
My cynical take: this is by design. Those web committees are staffed by companies that each have their non-web platform they're pushing (or were, until it died, see Microsoft), so even the most well meaning members are somehow contorted into compromises that make the web as a platform a bad technical choice in terms of actual design, but the best one in terms of flexibility and of course ubiquity.
It's completely stupid HTML, by default, doesn't have basic controls found in EVERY UI toolkit since circa 1980. The standard examples being ListView and TreeView.
> It's completely stupid HTML, by default, doesn't have basic controls found in EVERY UI toolkit since circa 1980. The standard examples being ListView and TreeView.
This is one of my greatest frustrations with the web as a platform. These controls are so basic they should just be there, eliminating the need to sift through dozens of third-party implementations all with wildly varying feature sets, performance profiles, framework compatibility, levels of upkeep, etc to find one that works for your project.
Well, they're not, and I can't find any good reason for why they aren't, when we're putting entire GPUs languages in there, except for the fact that somewhere in the HQ of one or more of those companies guiding web standards there is a discussion that goes something like:
Web Platform Dev: Boss, can we add TreeView to HMTL?
Web Platform Boss: Sounds cool, what are the advantages and disadvantages of doing this?
Web Platform Dev: Advantage: cross platform widget that's going to be super useful to many developers, replacing 3rd party ones of varying quality. Disadvantage: would take N months to implement and M years to have full adoptions, and yeah, it would probably increase adoption of the web platform, maybe even on mobile platform, where there is a chance that indirectly we will lose about $1-2bn per year from our walled garden, coupled with other web platform enhancements we should also make, regarding progressive web apps, local storage, etc.
Walled Garden Boss: Hey, SVP, can we please FIRE Web Platform Dev and Web Platform Boss as what they said amounts to a 2% drop in our share price?
Don’t attribute to malice… Many people working on frontend came from application or backend development and preferred the JavaScript model to a more declarative one. Not understanding enough the document context that drives the web. This makes everything more fragile and slow but hey “functionality” wins over everything else in todays world.
This doesn't explain ListView and TreeView. Or the lack of a DatePicker widget.
Look at Windows, MacOS, iOS, Android, Gtk, Qt.
Which of those doesn't have these widgets?
I'm tired of defending mega corps with thousands of employees with IQs through the roof, working on this for decades. It has to be latent malice. Banality of evil, if you will.
It is possible for normal everyday people to make contributions to the standards. I'm sure if you created a patch that showed these things working in firefox/webkit/chrome and wrote up a proposal and sent it to the correct listserv, you would at least have something more than baseless conspiracy to be mad about
I'm not a C dev and it's not my job to do something when people are literally paid for this stuff, a lot more than me. Every mainstream OS has what I'm talking about.
Definitely one place htmx can be abused is oob-swap: https://htmx.org/attributes/hx-swap-oob/, which allows any given HTMX request to replace any part of the page. It sort of destroys the concept of locality of concern that HTMX pushes for.
One example of this is the lack of an include-tag that could fetch a fragment from the server (useful for headers/footers). Developers have wanted it for decades and have been forced to reproduce the functionality themselves using frames and/or javascript.
Htmx users, can you please share your backend stacks and approaches? Me specifically interested in templaters for node (+ts) and your thoughts on endpoint management, but all ideas are welcome I guess.
The way maud lets you compose markup works very nicely with htmx. The HX-Request header lets you know if the request is coming from htmx or if it is a regular request. You either call the top-level function if it's a regular request to get the entire page rendered, or call a subset of functions to get the appropriate partial rendered if it's an htmx request.
It's also nice to easily have tests for the rendered pages. My unit tests cover verification of the rendered HTML, too.
Go: go templates and fiber for http serving. I have a mini framework for adding some structure to the templates (folder per feature: contains controller, templates, etc, and some naming conventions)
Django user here. HTMX fits in perfectly with the Django templating system. A fairly common approach is to use the same view but check for the HTMX header and then return a template file with the specific bit of HTML being swapped. There's also work in the Django space to be able to return parts of a template based on the request, which will suit HTMX perfectly too.
Well, as I expected, templating is the hardest part of migrating to htmx on nodejs.
After reviewing few templaters/etc (handlebars, ejs, lit-html, virtual-dom) and few abstractions (html``, just ``, h()), barely anything seems too easy and too freedom-y. Arcane syntaxes, high character noise (ejs, lit, js), lack of typing (all non-`` based), trivial screw ups (virtual-dom, handlebars), experimental status (lit ssr). Sigh.
Most people prefer templ but I don't like logic in templates, I just want to parse values. I keep different states in different template files.
Each template file is a portion of a full page which makes it easy to create an endpoint that pulls the partial with the latest values. HTMX can then hit that endpoint to load or refresh values.
Endpoints are usually
domain/page/partial
so if I'm on a configuration page at
example.com/config
then the endpoint for the privacy settings partial would be
example.com/config/privacy
Going directly there in a browser would get a 404 because I check for the HX-Request header.
Endpoint handlers return a processed template with the current state. I use those functions to both compose the full page on the backend, and to build the output for the partial endpoint.
I don't automatically expose all partials. I add endpoints as I need them. This is probably more idiomatically Go than anything to do with htmx.
Htmx + Kotlin with ktor and the html dsl was really fun to play with on a personal project. Static typing, autocomplete and a full-fledged programming language available to use in your html markup is a game changer. I was structuring my endpoints as pairs of "data" and "render", where the render endpoint just reused the function for the date endpoint.
True, it works just fine. But doing non trivial things in a templating language never quite sat well with me. So I am trying out dominate as a way of just doing everything in Python. Jury is still out though.
NestJS with Handlebars templates. I don’t love Handlebars but I have past experience with it so was the most pragmatic choice.
I’m interested in trying EdgeJS as a templating alternative to HB but haven’t got round to it yet.
I’ve added a NestJS error handler that looks to see if the request came from an htmx request and then serve the error response as html, if not then it sends back json since I do have json api end points as well in the back end.
perl + Template Toolkit (using the underdocumented support for the fragment pattern with EXPOSE_BLOCKS), before finding htmx we used Jemplate, which let you compile Template Toolkit templates into Javascript functions
My hot take: We initially used this library to allow us to iterate faster. But its is a pain once you reach a certain point, where it doesn't make sense to have this type of logic in HTML. I especially don't like how this library does error handling. I feel like this is the new jQuery. There is better way to represent interaction logic with open JS standards like Web Components.
I just want to take advantage of this news to say: I love HTMX so much! :D It makes web development fun again. I can still use all the fancy js libs I want -- but my main logic lives on the server, using plain HTTP and HTML. Really clear and simple.
Has anyone here used htmx for embedded devices? That is to provide web UI served by the device, for configuration / data access / control?
Can you share the experience and if you would use it again?
i havent used htmx yet, but it sounds like a breath of fresh air. no npm library with 1000 dependencies with slow build times. just plain simple js library like the good old days ^_^
Vue? Svelte? Preact? Solid? Even Angular is much saner than React. Nobody needs to use React. Never had to. HTMX is no alternative for highly interactive web apps, btw.
I'm probably totally ignorant, but how would htmx work with a static site generator? Isn't the whole point of htmx that it extends the front end to dynamically interact with the server and get responses to inject?
You could have static elements pre-rendered, but only loaded on demand. For example, if you had a blog with comments, you could have the comments pre rendered in htmx fragments, but only loaded when they are clicked.
Or a photo gallery with thumbnails that are enlarged when clicked.
On a documentation site, photo gallery, etc, it is very reasonable to use something like htmx to implement navigation without triggering full page loads.
Anybody know if there’s something like HTMX that plugs into Turbo? Every time I start using a stimulus controller, I have the thought that it should be more like HTMX instead.
It has already been pirated by various groups and made available for download assuming you have the bandwidth. Unbelievable. Big Sky has to make money somewhere.
The app is now chock full of htmx interactions and has very little client side JS for the size of the app and it’s a joy to work on.
Without htmx I would not be able to turn around features as quickly as I do for the wider team so thank you, thank you, thank you.
I’ve been in web dev for 20 years and this feels like what we should have made all along.
The one area I would like to see some development is the file upload experience, I’ve had to do something a bit weird to get htmx and dropzone playing nice.