by mtillman · 3y ago · 0 comments
>Why should only <a> and <form> be able to make HTTP requests?
>Why should only click & submit events trigger them?
>Why should only GET & POST methods be available?
>Why should you only be able to replace the entire screen?
>By removing these arbitrary constraints, htmx completes HTML as a hypertext"
I guess people do all of these things with javascript anyways but it gave me a "get off my lawn" reaction when I read these bullets.
I'm itching to compare notes.
There's a lot to say about it, but the essential idea is that if you let the server control the state of the application via hypermedia requests/responses, you eliminate a lot of the complexity that is associated with client-side web apps.
Yes, I get that duplicating state on the client and the server is a headache. But are people really doing that? You're just moving the state toward the client and keeping the backend much more thin. Are we going to ignore the past twenty or so years of CPU improvements? I'm not saying just yolo it and do loads of pointless expensive work on the client but 5G and modern phones should have some place in this calculus.
I personally find consuming JSON APIs cumbersome and prone to errors. It seemed like a great idea when we first started doing it, but these days I'm keen to explore other options. I'm under no illusion that HTMX doesn't have it's own tradeoffs, but I like the return-to-tradition approach it's taking.
But we are talking mostly about developer-experience here and while that is great, it is a compromise compared to user experience. Getting a little delay for an ajax call on much many more interactions is a thing and its there. Maybe that makes sense for many but it should be noted just like deciding to write a react PWA instead of a fully native ios app is a tradeoff for developer experience (or a dozen other reasons) instead of user experience.
Type synchronization is becoming a very popular story. Now I get IDE awareness of all my endpoints and whether I'm using them right.
Not saying you have to prefer it, but some of the htmx articles imply there is a difference.
Look at your average JS frontend and you'll find stuff way worse than the things you're complaining about wrt htmx. Live and let live, as they say.
To clarify, if you just use a bit of react that would work well with HTMX. But how many sites use a bit of react without a larger framework wrapped around it?
https://www.reddit.com/r/htmx/comments/160uuzd/whats_the_dif...
Therefore "Just use Phoenix". It's like saying manual transmission cars suck, just learn to fly a plane.
I think the learning curve is not all that steep.
Finally the forth function render/1 receives the assigns argument which contains the :val state and renders the template using the @val template variable.
The render/1 function renders the template included in the function. The ~H""" syntax just means "treat this multiline string as a LiveView template" The ~H sigil is a macro included when the use Phoenix.LiveView is invoked at the top of the file.
The resource looks excellent, but I think it demonstrates that this is more complex than the equivalent Rails.Which is not even a criticism of Phoenix - it obviously has a lot of power, and "scales right up TM". But I wouldn't think it was a "just do this" kind of a thing.
So here's a response from the "get off my lawn" crowd.
It's about hypertext. It's always been about hypertext. HTTP is literally "Hypertext Transfer Protocol". The term Hypertext was coined in 1963.
Without Hypertext, Javascript is nothing.