Htmx 1.9.0 has been released
htmx.org
htmx.org
I discuss it in an essay here:
https://htmx.org/essays/view-transitions/
Chrome's docs on the feature are here:
https://developer.chrome.com/docs/web-platform/view-transiti...
MDN:
https://developer.mozilla.org/en-US/docs/Web/API/View_Transi...
will be exciting to see this feature rolled out across the major browsers, as it will make vanilla HTML a lot smoother.
you have a typo on that page under https://htmx.org/essays/view-transitions/#the-css : @keframes instead of @keyframes
but it's not finalized yet. View the very interesting dashboard here: https://mozilla.github.io/standards-positions/
> We're supportive of View Transitions, but since it's a new capability for MPAs in particular, we think it's important that the solution works well for MPAs and that it's consistent with the solution for SPAs. As such, if design changes are needed for the MPA use case that also affect SPA API, the latter should be updated as appropriate even though it has shipped. In other words, we think it would be bad for the SPA and MPA APIs to diverge or be inconsistent.
I don't think that's undecided. More like, "positive with some reservations".
edit: When I think about it again, perhaps you are right given the issue is still open (but also "ready to add").
edit2: Thinking about it more, I like the open process and all but perhaps such discourse should be private before being finalized as early commenters from Mozilla can have a premature influence on public opinion.
No, it shouldn't. It's a good thing all discussion is happening in the open. See how Firefox devs still have their reservations but Chrome already shipped it to prod completely ignoring any such reservations.
More spec proposals == good for your career.
Shipping a feature (even if it's non-standard) == good for your career.
Ensuring standard-compatibility == noop.
Source: I used to be a browser dev annoyed by how Chrome kept shipping non-standard features.
As long as Chrome has > 80% market share, the more non-standard features the ship, the more they cement their position.
Same as IE6, which was intentionally non-standards. Sites would be designed to work in IE, and would not work on Netscape.
Considering how much spying and how much lock-in Chrome provides for Google, anything that makes devs design for Chrome only is a huge advantage.
We still had to build an API anyway for external organizations using our product, but you still skip a ton of unnecessary JS code.
0. GalenAI.co
For instance, if I have some sort of utility button, and say I put it in "utility_button.html", a template file. In practice, I might have to supply different actions, or icon names, or colors when the button is generated, which means that each of these potential variable needs to be a template parameter. Adding a class involves some string manipulation magic.
On the other hand, on most client-side front end library, when using a template, I can still slap whatever attributes onto the element, or manipulate its classes as an actual list with relative ease, because front end libraries are more or less already a big HTML parser and generator.
One comment on the UI, on my phone it was not obvious that adding the topic tags was working, because they get added off screen. I was just clicking "ancient-greece" like an idiot for 30 seconds then I accidentally scrolled down and saw what was happening.
One UI note, the layout jumping around when typing or clicking on things is a little jarring. E.g., the "Word is too short" message pushes the field the user is typing in down the page.
I don't see any network requests being sent.
i intentionally introduced an 200ms delay so that you can see things like request indicators:
https://github.com/bigskysoftware/htmx/blob/master/www/stati...
https://htmx.org/essays/hypermedia-friendly-scripting
In general, I'd recommend perusing the essays to get a flavor of the style of web application we are advocating for:
And, if you want more, taking a look at our book:
https://htmx.org/essays/a-real-world-react-to-htmx-port/
in which improved performance features as a big part of the realized benefit of the conversion
of course, not every application is going to be amenable to a hypermedia-style approach, so your mileage may vary:
It's heavy client-side frameworks that often feel slow.
With some constraints you can create a page that works with or without JS. The same endpoint can be used for serving HTML fragments for HTMX and full page for JS-disabled clients since the HTMX request can be detected by the HX-Request header.
Didn't that used to be called AJAX or REST or something?
https://enmascript.com/articles/2019/09/26/toggle-content-on...
I don’t like messing with the URL to achieve this, so unless using the “details” element, maybe JavaScript is actually the best approach…
I'm sorry if my question is not sufficiently informed, but how does HTMX not "use JavaScript" to trigger animations?
Have followed the library and approach for a while and tend to compare it to Alpine, which I find a bit more intuitive.
But that's probably exactly because Alpine isn't shy about the fact that you're writing JS in the end.
I found such solutions (Alpine) a grrat joy to start working with (e.g. a complex form with nested fields, custom autocomplete...) and a nightmare to extend or generalize.
The Chrome transition API is very interesting. Also, there certainly is a place for controlling JS via HTML.
But for the risk of sounding inpolite:
Having read a couple of posts by htmx team, the "htmx is hypermedia, SPAs were invented because X and are a crutch" style intro starts to feel a little repetitive and dated to me. Every post starts with a bashing of "SPAs", it gets tiresome very quick. SPAs can be simple, they can be complex nightmares.
So can HTML-centric "sprinkles of JS" that outgrow their purpose.
Also, who are these "cool kids writing SPAs"? It's 2023 and it's irrelevant if you generate your HTML in PHP, JS, Rust or Python: you need abstraction and modularization for large frontends.
That's the problem React solves, not just fluffy page transitions.
Yes, it's just that some of us prefer to leverage our existing stack (ie. abstract and modularize with Django/Twig templates) than adding yet another layer to the lasagna. Nothing against SPA frameworks (ex: we do use Vue/Vuetify for some apps with complex user interface), but there are many cases where it's actually just bloat.
> > it's irrelevant if you generate your HTML in PHP, JS, Rust or Python: you need abstraction and modularization for large frontends.
> Yes, it's just that some of us prefer to leverage our existing stack (ie. abstract and modularize with Django/Twig templates) than adding yet another layer to the lasagna. > Nothing against SPA frameworks (ex: we do use Vue/Vuetify for some apps with complex user interface), but there are many cases where it's actually just bloat.
Sure, I agree with you!
What I don't like is the contrarian attitude of htmx team and the pretence of not using JavaScript. It's just progressive enhancement, a valuable and very old approach.
IMO, an approach best implemented without a "framework" like HTMX.
I mentioned Alpine, because I think in combination with blade "components" (which are just fancy template partials), I think it's better than HTMX (subjective opinion). Still, I'd advise against Alpine and for a simple external JS file for anything more serious than an MVP or a landing page.
Kudos to the htmx developers, who made a library out of their idea of progressive-enhancement JS.
My point is just that I don't like two things which seemingly repeat in each of their blog posts:
- They define their own language around REST and hypermedia to explain a string-language in HTML-attributes, which is then executed by JS. It's really not much different from Alpine. It's called "progressive enhancement" and a DSL in HTML attributes is not needed to implement it
- They start most posts about their library with a lengthy ramble about "cool kids and SPAs" vs "good old server-rendered HTML". This is a tiresome trope.
The first time I read their "HATEOAS / Rest is for humans" article, I found it witty. The second time I read an article explaining their appproach, I found it interesting.
By now, I just skip all the htmx stuff and jumped to the meat of the post, the new (JS!) API for page transitions.
I'm not really interested in learning a new "JS-in-HTML"-language.
TL;DR: Have you ever heard of frontend-fatigue-fatigue? :D
I wrote lots of vanilla JS which abused HTML attributes in similar ways.
For a simple landing page, I'll probably try htmx some day instead of writing this myself.
But I tend to not like this whole approach of "magic strings in HTML". When I do this in my own code, the point where an internal alarm rings is usually when HTML attributes start referencing comma-separated lists of unchecked... somethings (usually IDs).
I know nothing about Alpine, will check it out.
E.g. these are examples for what I meant by "DSL in HTML attributes":
<input type="text" name="q"
hx-get="/trigger_delay"
hx-trigger="keyup changed delay:500ms"
hx-target="#search-results"
placeholder="Search..."
>
<div id="search-results"></div>
In the end, of course, standardized HTML has DSLs in attributes too (e.g. srcset, sizes...).Using the word "magic" might have been a bit snarky, that's always a question of definition.
I meant that the behavior is neither standardized nor simple code that can be read as such. With Alpine it's the same, it's code in HTML attributes, but not all regular JS rules apply.
The first example for the transition from the release notes is another one:
<div class="sample-transition">
<h1>Initial Content</h1>
<button hx-get="/new-content"
hx-swap="innerHTML transition:true"
hx-target="closest div">
Swap It!
</button>
</div>
Strings like "innerHTML transition:true" or "closest div" and the whole thing in combination are just not too much my taste, and I find that this is not really simpler than just writing JS.But I can see how it fills a niche and I don't want to argue against this idea as such.
Just the presentation I can't understand.
HTMX is not an "extension of HTML" for my understanding, it's a JS lib that parses non-standard attributes using a DSL. Doesn't need to be bad.
Regarding the "download" attribute: I love it too, and I always love when I find out I can do something easily in HTML and CSS without using JS. Similar example, maybe not useful so often: the form attribute.
It's a DSL, sure, I won't argue about that. Matter of taste I guess, but I actually find this example you posted super easy to read, even the hx-trigger value. That's precisely what I like about HTMX: you get quite a lot done in a few attributes, while still remaining very readable. If the attributes value is too complicated or too long (ie. difficult to read), I would probably rewrite the logic in a simple JS function anyway.
> I always love when I find out I can do something easily in HTML and CSS without using JS
Ditto. When I wanted to play a media, it used to be some bad combination of flash object with JS bindings... now it's just a single audio and video tag. What a time to be alive...
we have never said that SPAs are a crutch, our (really, my, there isn't much of a team and I don't speak for anyone else) claim is that SPAs are as popular as they are for advantages that are not inherent to them when compared to hypermedia, and htmx tries to narrow that gap
i am sympathetic that people reading the various essays on the htmx website might get worn out by my repetitive beating on hypermedia, but consider that for every repeat reader, there are tens or hundreds of new readers who haven't heard much about or thought much about hypermedia. Repetition is a key to teaching, and I teach, so maybe that influences how I write as well.
regarding abstraction and modularization being key to large front ends, I sort of agree to an extent, but I think that at the system level that abstraction can be hypermedia and that the modularization can be done server side
of course it always depends on the app, htmx/hypermedia isn't right for everything, etc. etc. as we try to point out in an essay on our site:
https://htmx.org/essays/when-to-use-hypermedia/
do I get a little punchy about SPAs at times? Sure, it's the internet after all. I've been fighting for the hypermedia-oriented approach for web development for a decade now, and I've been called "old", "irrelavent", "pointless" and "stupid" many times along the way by SPA fans. There is obviously some conflict between my views on web development and the larger front end world's perspective.
But I try to be reasonably balanced about the tradeoffs, even while I think that the SPA approach is dramatically overused today.
First impressions from someone who's had a hand in many large scale consumer centric UI's.
- I have a decent grasp on hypermedia as a concept. Not sure why I should care
- The focus on hypermedia strikes me as dogmatic
- it brings me back to the holy wars of gatekeeping "restfulness"
- or the battle to strictly adhere to semantic web
- Nooo, style classes can't be used in markup! that's what selectors are for and I'll literally die on this hill
- In the middle of the restful holy wars at least everyone could agree allowing clients to query data was insanity. Insanity i say!
- ok maybe graphql makes a little sense
- The htmx value prop seems to be scattered - people who value "hypermedia"
- devs who have "javascript fatigue"
- based on sentiment I've seen users tend to be the latter
- As far as the tech itself (again quick first impression) - i feel like the "api" is somewhat over-abstracted
- seems like much of the functionality would be a jquery one-liner but with the syntactic sugar of using html
- this pattern taken to the extreme reminds me of coldfusion markup and I don't mean that disparagingly!
- jquery is popular bc the api strikes a great balance between over/under abstraction
- syntactic sugar, effective primitives, plugins for the rest
- to contrast htmx seems to emphasize high-level functionality
On the ideological grounds of "semantic web" having logic and tags sprinkled thru the UI feels questionable and challenging from a unit testing perspective.- Given a code sample with the exact same syntax what benefit is there to template/interpolate on the server vs the client side? The downsides seem pretty big. Strings with "X time ago" become stale. More network round trips. Interpolated data has to be parsed to be queried locally, but I guess you could add another network request. Given the typical react/SSR setup I don't even have to think about server vs client side and benefit from both worlds. Anyways sorry for the ramble - I'll be following!
I evaluated HTMX as a not-js way to do modern web apps. It was fine, it was certainly interesting. I had some concern about how much pain I would be in for when I inevitably wanted to borrow something from the js ecosystem, like a charting library or something.
I actually ended up deciding on godot with gdscript and while I'm not done yet, I'm having a pretty dang good time. I'm a little annoyed that I have to pay apple to get it on iOS, but I have to pay apple anyway because safari is such an annoying odd one out from how firefox and chrome's renderers work. It's always safari that has weird things it doesn't like, in my experience. And I have hope that either Epic Games or Europe will manage to force Apple to let people sideload apps.
also, I think it is possible to make it not tick from time updates, but only from input event updates, or maybe an animation actually running. similar to what the editor does.
Native apps (i.e. iOS, Android, MacOS) purely in HTMX is probably not its sweet spot. Probably Electron (or Godot) would be better.
which is discussed in depth in our book:
https://hypermedia.systems/book/hyperview-a-mobile-hypermedi...
Oh, this was only on iOS and macos Safari, of course. Worked fine on FF/chrome.
Asking because of my limited knowledge. If you happen to have a blog post or something on that, would be helpful.
HTMX is not too different from Jquery in terms of how it works so it is compatible with most if not all JS libraries. In my case I have
<script src="https://unpkg.com/htmx.org@1.8.4" integrity="sha384-wg5Y/JwF7VxGk4zLsJEcAojRtlVp1FKKdGy1qN+OMtdq72WRvX/EdRdqg/LOhYeV" crossorigin="anonymous"></script>
<script src="https://d3js.org/d3.v7.min.js"></script>
in my header and I write JS that uses d3.js from a <script> tag, I am not messing around with a Javascript build system but I see no reason why you couldn't have a react app that is compiled and lives in a <div> inside an htmx page.A large part of playing nice with other JS libraries is that HTMX works with the DOM in the browser, instead of creating a Virtual DOM (VDOM) like React and Vue (and others, eg. Solid.js) do, which leads to a lot of libraries only working with those platforms they're made for. Which is a great tragedy IMO.
A long-standing frustration for me is that I always felt like it was really easy to make a responsive layout with Swing (I know desktop apps don't deal with quite the gamut of weird aspect ratios that websites do, but for the apps I built users typically tiled them and resized them between portrait/landscape and various sizes based on need and if they were actively using them or just passively monitoring them. So a lot of the considerations felt very similar compared to modern web design), whereas in CSS it's such a struggle comparatively (though flexbox and css grid and several other similar things have improved it a lot).
Now that, compared to godot, godot feels a lot more like the productivity/design experience I got out of Swing and friends.
Seems it was discussed a few months ago[1]; I missed it then.
> It’s worth mentioning that, if you prefer, you can use the data- prefix when using htmx:
> <a data-hx-post="/click">Click Me!</a>
I only ask because I kind of wish such a thing existed.
I still can’t find a happy medium between no JS and “browser as an entire OS”.
Not sure if it's possible for htmx to work with haserl or some c-based cgi or even lua-based lightweight web framework, I guess it could, just not popular so nobody did it.
<div hx-preinsert="myfunc">Old Content</div>
<script> function myfunc(callingElement, serverResponse){
return modified-Server-Response
}
IMO, aside from the fact that such a feature really is needed, the lack thereof pushes people to Marko, Livewire, etc, simply because they need to do add some tiny detail which is available in the JS. Besides that it makes HTMX look like a toy that values purity (no frontend JS) over practicality.I know there are ways to build a plugin, but do not have the time or headspace to figure it out.
<button hx-get="/example"
hx-on="htmx:beforeSwap: event.detail.serverResponse = transformResponse(event.detail.serverResponse)">
Example
</button>
In general, htmx is going to lean on events for integrating scripting into the hypermedia flow.I had developed sites for 25 years. I still have a corporate site that was developed 20 years ago, and it returns more results, and is faster to render than most of new fangled SPA I seen deployed on servers 20x larger.
I do agree with you that SPA (react and its ilk) have cleaner benefit of composability of components, but I would posit that AJAX and component state/props has made for less reliable web. I often find myself in situation where SPAs crash mid way during concert or flight purchase - be it JS error, or network instability. Reloading the page doesn't get SPA to resume where it crashed, but often throws additional errors, saying I am already mid way in checkout (but I can't continue), or invalidating session (but still remembering that my other session was in process of buying a seat, so I can't reselect the seat I wanted. Finally, they are terrible for bookmarking or sharing.
So the composability of components, a benefit, came with a need for developer to be extra careful about failure modes, resuming states, bookmarking directly to specific content. Most developers are not careful, and the old html per page model forces different mentality for dealing with failures, and content availability.
1) Annoyed by page refreshes
2) SPA's is a special skill now, frontend developers take pride in knowing everything about React, Vue, Angular and spending hours and hours updating their NPM dependencies. How can they justify all the time spent if it's not almost like a science?
3) Separates the frontend guys from the backend guys. Technologies like HTMX allows the backend developer to pretty much do the whole job, which concerns a few people.
I've looked a bit for examples of HTMX in the wild, and the only times I've found it it's been so slow I would have preferred a full page refresh which at least lets me bookmark/navigate properly and involves no JS at all. Not enough data to really form a strong opinion though, I freely admit.
I've seen that quite a few times. Basically moving the entire business logic to the frontend, so that the backend can remain elegant and generic (yet somehow complicated too). In the end it actually makes for a slower app experience and may cause insane complexity on the frontend.
But backend developers often need or have a desire to build a perfectly usable frontend for their service, without relying on a frontend person to start with. This could be due to project ambitions or budget.
but...
am i out of touch?
no, it is the children who are wrong...
Don’t mistake activity for achievement.
I would recommend reading the essays on the htmx website for more in-depth discussion:
I've given a real, honest effort to using the shadow DOM for a bunch of WebComponents and it just seems like it makes everything harder for no benefit that I've been able to find. Every example I've found of WebComponents using the shadow DOM seems to show many many lines of weirdly-inverted HTML (templates/slots) and JavaScript, all to achieve what I can do in a few "document.creatElement"s (vanilla JavaScript) that are easier to understand. And using the shadow DOM means my global CSS styles don't apply to what I do there without absurd hacks.
I have honestly been looking for a benefit here, but I just don't see it. What am I missing?
Only the shadow DOM provides some relief from this annoying part of web development.
I understand that precompiling is an extra step, but the React codebases that use shadow DOM are doing precompiling anyways (tsx), in which case it doesn't make sense anymore.
The state of code distribution in js is pretty sad IMO. Most es modules are faked. I would like the opposite of Vite where the real es modules are in production. Modules aren't just treated like a toy in other languages. :(
About Vite: I agree, it's not how it should be done. Svelte components should be compiled to real modules with real, easy to understand paths. I would love to use a system that actually I understand, and just compile things to module imports. We could hack it together maybe, it's HackerNews anyways :)
In my experience when I start running into problems with competing styles it's usually because I've not structured my CSS well, although admittedly, structuring your CSS well is pretty hard to do.
Also the styles may contain variables and those can be inherited. So the design can be shared even if you aren’t pulling in shared styles.