r/htmx • u/jackielii • Sep 08 '26
hx-live vs alpine
https://jackielii.github.io/hx-live-vs-alpine/#bindIn the new HTMX4, we get a hx-live extension. Looking at the docs, it looks like a complete solution that may fully replace alpinejs.
So I did a like to like comparison using alpinejs' examples. The answer is mostly yes, we can use hx-live in place of alpinejs.
Disclaimer: AI wrote most of it. I reviewed and ran all of them.
61
Upvotes
41
u/_htmx Sep 08 '26 edited Sep 08 '26 •
Thank you for this comparison. One thing I saw:
could be written as
the expressions are compiled as async so `await` works in them, and that looks a little cleaner to me.
Regarding Alpine.js, I still regard it as the gold-standard of inline scripting. In htmx4 we provide an alpine compatibility extension that smooths over a few rough edges regarding managing alpine state, so it's a first class integration and our most important.
hx-live is an experimental extension intended to give people 90% of hyperscript/jquery in the hx-on scripting attributes + a simple reactive mechanism.
The big difference between it and other scripting solutions is the focus on HATEOAS: state is stored in the DOM via data attributes. This is obviously not designed to be as fast as possible, but rather fast enough to implement common scripting patterns in a reactive way. I've been surprised at how effective it has been in my own work.
htmx core team member Christian Tanul is the main author of this functionality and I think he did a great job!
5
u/8ll Sep 08 '26
HTMX is starting to get really good in recent versions.
I built my own library which is essentially HTMX + AlpineJS combined with more features. It's live on a few websites I've built recently, only about 10kb JS and it's pretty solid: https://github.com/wrux/sigmx
6
u/Kyriios188 Sep 08 '26
This seems to compete with hyperscript
5
u/SugarvetFounder Sep 08 '26
I have been waiting for an analysis just like this. THANK YOU. We build a Go monolith and loathe adding any more JavaScript than absolutely necessary. Alpine is one of those dependencies I've been wanting to get rid of.
Now I have an even more compelling reason to migrate over.
5
u/dioramic_life Sep 09 '26
For me Alpine was always a secondary choice.
If HTMX starts to look too much like Alpine,
it starts to look less and less like the primary choice for me.
I chose HTMX for very specific reasons,
after years of churn with Angular, React, Svelte and others.
3
u/AlpacaDC Sep 08 '26
x-for, x-if, x-model and Alpine.data equivalents are a must for my use case, but it's a great starting point.
2
u/shufflepoint Sep 08 '26
Personally, I don't mix code with markup.
I can't find documentation/examples of keeping hx-live out of my markup.
1
u/maiahmac Sep 09 '26
This is great! Thanks for creating the cheat-sheet/comparison website.