Тёмный

HTMX: What's Old is New Again 

CodeOpinion
Подписаться 86 тыс.
Просмотров 16 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 111   
@KimHogeling
@KimHogeling 3 месяца назад
We made two actual applications with HTMX and we and our clients are very happy with the results. Our software architecture is disciplined and simple. Data and logic live in storage/repository/service layers not within controllers, this way non-html clients like a Swift or Kotlin app consume dedicated controllers which do consume aggregated data from the services but simply don't parse it through views. (To be clear with my terms; service is not an api or micro service, it is just a technical layer inside of an application that prepares data for controllers). Anyway long story short, its very refreshing to have such a simple way for building pretty advanced HTML applications with very little JS code.
@outwithrealitytoo
@outwithrealitytoo 3 месяца назад
"Our software architecture is disciplined and simple"... so many technologies try to make up for a lack of the former with a lack of the latter. Inheritance, microservices, ORMs, anything which has the word framework in it's description, (I would say, "types" but let's not go crazy, structured data carries semantic value) all try to prevent poor code by necessitating convention. As an example, microservices don't make your components modular and loosely coupled they necessitate it... sometimes that works sometimes that doesn't but one thing it always does is increase overheads. If your microservice is a singletone speaking to a singleton I do not think your interface is not doing what you think it is doing. A JS application on the browser is leaky control logic, Control logic that must be replicated on the server to avoid security reasons. Keeping the two lots of partial logic in sync... urghh... you need a framework for that. htmx still requires JS on the browser... for specific behaviour of specfic widgets and bespoke widgets. (sorry JS, for visuals html5 and css done ate your lunch).
@buriedstpatrick2294
@buriedstpatrick2294 3 месяца назад
This point about data representation is super important. Different contexts call for different representations of data. Not sure I will realistically be using HTMX anytime soon, but I like the idea of delivering the format that the consumer actually cares about, since it carries intent with it. As in: This is HTMX, use it in a browser. Not: This is JSON, use it to perhaps eventually render it in a browser.
@CodeOpinion
@CodeOpinion 3 месяца назад
Exactly
@ShawnThuris
@ShawnThuris 3 месяца назад
I work on a large, fairly busy server-rendered Perl site that's under active development. Many bits and pieces of interactivity were added over the years, first through jquery and lately with vanilla JS. I could definitely see adding HTMX to the mix.
@joga_bonito_aro
@joga_bonito_aro 3 месяца назад
I'm currently trying this out with Golang and Templ (for HTML templating). I have to say, before using it I was sceptical... But after a few basic usages... I kinda sorta fell in love with it. In Go and in HTML that is. Especially the handling of state is way easier since the truth state is always on the server. Don't try to be smart. Make it dumb and simple. PS: the htmx inventor recommends having two separate endpoints for json/HTML responses instead of handling it using accept headers. I think it was on a primeagen stream.
@hessianbeard
@hessianbeard 3 месяца назад
Used it a couple weeks ago to make a small internal admin site, it was great fun
@BTFranklin
@BTFranklin 3 месяца назад
I appreciate this kind of thoughtful analysis, delivered in a straightforward and time-efficient format. Thank you!
@CodeOpinion
@CodeOpinion 3 месяца назад
Thanks!
@capability-snob
@capability-snob 3 месяца назад
Null Labs also had a really solid video on this, looking at the creators older projects, explaining that it's largely about round trip latency; and tbh we've already got great tools for that.
@falldowngoboone
@falldowngoboone 3 месяца назад
I'm not sure we "lost our way" with the DOM manipulation libraries and JSON requests, etc. Frameworks were created out of a real need (e.g. slower internet connections, HTTP connection bottlenecks, etc.), so doing all the work on the browser made more sense. The tradeoffs, however, became more and more apparent the further we moved into JavaScript land on the front end. We all of a sudden had to think about things that the browser traditionally did much better, like routing and scroll position management. If nothing else, JS DOM libraries have galvanized what is important in native browser concerns, and helped steer us to the current state of the Web. BTW, I have been loving your channel since discovering it a couple months back. Great content!
@bobbycrosby9765
@bobbycrosby9765 3 месяца назад
These javascript frameworks were created because Javascript code was becoming large and complex because of very complex, very interactive frontends. In fact, things like reactjs are still better in this scenario. But people used them when they didn't require complex Javascript code because That's What Facebook Uses, and then, because That's What Everyone Uses. To be fair, popularity is a valuable metric: it's easier to get help with it, it's easier to find a job, easier to hire, etc. Also, reactjs came out long after internet connections were generally fast.
@CodeOpinion
@CodeOpinion 3 месяца назад
Thanks for the comment. In practice, as you mentioned the further we moved down the road, more data (payloads,js,bundles,etc) was sent down to the browser, which was the exact opposite of what was needed if the concern was slower connections, bottlenecks, etc). I have always been left scratching my head with the reinvention of routing because it was forced with the model of a SPA.
@NoahNobody
@NoahNobody 3 месяца назад
I've heard a lot of people try to explain the core reasons for htmx, but this is the best one I've seen.
@Tony-dp1rl
@Tony-dp1rl 3 месяца назад
HTMX absolutely rocks.
@Kekszmester
@Kekszmester 12 дней назад
HTMX is just a fresh air. I did lot applications in react and wrote backend in golang. React always felt overcomplicated, with all the hooks, libs and so on. I do mostly dashboards, and HTMX is just the perfect fit. Every feature needs at least 40-50% less time to deliver. I definitely not go back to react.
@CodeOpinion
@CodeOpinion 8 дней назад
Yes, I think it's entirely dependent on what you're building ultimately. As always some tools fit better situations than others. I think the problem is we tend to use the same tool for every situation, when it's entirely overkill or not a good fit, often because it's just "what the industry uses"
@margosdesarian
@margosdesarian 3 месяца назад
I used the .htmx extention as a way for the Http module at the core of my CMS (in 2003 or something) to recognize that this was a page that needed to be served by my cms, as opposed to a static path or file
@EricBuitenhuis
@EricBuitenhuis 3 месяца назад
This reminds me of the old Nitobi components, where it used declarative html Ajax widgets.
@fennecbesixdouze1794
@fennecbesixdouze1794 2 месяца назад
A massive problem with what they're advertising: An HTML partial is not the same thing as HTML. I can't just go to /contact/1/edit and expect the website to render with the edit form. That GET request is just returning a partial. The glory of the old internet was if I had something like a Ruby on Rails scaffold, when I go to /contact/1/edit I get the entire hypermedia resource with all the hypermedia controls. I could bookmark that edit resource and come back to it and I'd get the same edit form. Of course I could do something more clever on the server to understand whether the request is over HTMX or a browser navigation, returning a partial in the former case and a full page in the latter. But I'm not getting rid of any of the added complexity of trying to do in-line edit, and I'm certainly not rescuing the simplicity of the REST model with HATEOS, statelessness, and the simplicity of collapsing resource and representation. Trying to get fancy stuff like in-line editing still means moving state and behavior to the client, and it still means giving up the simplicity and robustness of pursuing a REST design where we can represent something like an edit form as its own hypermedia resource rather than as a stateful on-client interaction.
@Htbaa
@Htbaa 2 месяца назад
htmx actually sends a header that tells your app it’s an htmx request, that way you can decide on rendering a partial or the entire page. It’s just a little check to add.
@CodeCraftHub-NAS
@CodeCraftHub-NAS 3 месяца назад
You mentioned ColdFusion and got a subscription for this Old Guy!
@CodeOpinion
@CodeOpinion 3 месяца назад
welcome to the old guy club!
@CodeCraftHub-NAS
@CodeCraftHub-NAS 3 месяца назад
@@CodeOpinion I started ColdFusion back in 1996 so I feel looking at your photo I might be older. LOL
@CodeOpinion
@CodeOpinion 3 месяца назад
I was writing perl in a cgi-bin at that time. I'm older than I look I guess 🤣
@CodeCraftHub-NAS
@CodeCraftHub-NAS 3 месяца назад
@@CodeOpinion How cool I did Perl as well. in fact Randal L. Schwartz once gave me a tip on how to fix something for Perl and Windows NT...
@jbeaudoin11
@jbeaudoin11 3 месяца назад
I haven't used htmx yet but i feel like the first step is to build an HATEOAS api/core and then put an htmx layer on top of it. But i'm still looking for a standard way to build the HATEOAS api (not htmx). If you guys found a good one (not a language, not a framework, a standard), let me know !
@ronaldosd
@ronaldosd 3 месяца назад
My favorite Stack for this is Go, Echo framework and a-h/templ for the templates Its amazing when you combine a templating engine with Htmx
@0xSLN
@0xSLN 3 месяца назад
​@@ronaldosd looks like a nice stack, at first glance anyway.
@jbeaudoin11
@jbeaudoin11 3 месяца назад
I'm looking for a standard that applies hateoas not a framework. I found a couple like HAL and HAL-FORMS but I'm not really convinced.
@nchomey
@nchomey 3 месяца назад
You can use pretty much any server side language for this - you just return html rather than json. That's it! Use php, ruby, go, or whatever floats your boat
@minhquando100
@minhquando100 3 месяца назад
I use FastAPI but I just use string formatting instead of jinja2 for creating my HTML templates.
@kublaios
@kublaios 3 месяца назад
Very well explained, thank you.
@TomEugelink
@TomEugelink 3 месяца назад
Hmmm, in my opinion the big difference is where state resides. With JSON pulled from the server, the browser usually holds state; code running in the browser using the state present in the browser decides what to request next. With HTMX the state seems to move back to the server. After all it needs to know what was selected, or in a cart, or whatever to generate the HTML. HTMX does not seem well suited to have browser side state and then send all that to the server to make sure it has all the data it needs to generate HTML. Or it becomes some kind of weird hybrid where it send partial... Nah, that would be a disaster.
@AndersBaumann
@AndersBaumann 3 месяца назад
You obviously don't get it. All state is on the server where it belongs.
@TomEugelink
@TomEugelink 3 месяца назад
@@AndersBaumann I don't get it? Okay. 😆
@habsi70
@habsi70 3 месяца назад
It is a matter of opinion or preference if the state should be stored in the server or client. You will always have trade offs. I much prefer SS state. But that’s how I am used to develop web apps for more than two decades. It suits me very well in most cases. If it works and is easy to maintain, then it’s the right tool!
@TomEugelink
@TomEugelink 3 месяца назад
@@habsi70 I've been developing SS for decades as well (and still am). And while SS increases control of the (performance of the) application, the client is just a dumb HTML display engine in that scenario, having the state on the server is not the most logical place. As much as I would like it to be, it adds complexity. The interaction with the user is in the browser, so it make sense that at least the state around the UI is there. It is not without reason the web-frontend-and-rest-backend became so popular; Rest APIs are largely stateless. And if the state is on the frontend, then the rendering also needs to be, otherwise state needs to be synced all the time (so the rendering backend knows what choice a user just made in select ABC or what have you). So rendering happens where the state is. And if one does not see the additional complexity with state on the server, then one indeed doesn't get it. 😄 The only real alternative is something like Vaadin in pure Java mode, but that is a niche approach. So the big difference of HTMX and the current web development is that state moves back to the server.
@habsi70
@habsi70 3 месяца назад
@@TomEugelink I think I understand. I am not sure if my bias prevents me from working more efficiently in the frontend or if the type of projects I do are just not that complex on the frontend. For now me and my collegues are more efficient (less time programming, better at maintaining) when using SS state. But i will keep your reasoning in mind in an upcoming project and validate it from that perspective.
@zonegamma8197
@zonegamma8197 2 месяца назад
Good video thanks
@purezero23
@purezero23 3 месяца назад
What if I have two clients that both use htmx but want the edit forms displayed differently?
@habsi70
@habsi70 3 месяца назад
Use different CSS? If the layout is completely different you have to serve different HTML. Even when rendering client side you would have two templates if the DOM differs that much.
@purezero23
@purezero23 3 месяца назад
​@habsi70 so I guess in this case you are tailoring your responses to the front-end. Feels like a hard coupling. But I think this an edge case that is hardly seen, more likely you would have the client just get the json response if they don't like html one I guess
@habsi70
@habsi70 3 месяца назад
@@purezero23 Exactly! Of course this is not always a useful way to create an app. In most of my applications we have a rather static backend where htmx fits very well. Where needed we provide the necessary interfaces for JSON, XML or whatever is required. React et al seems in these cases overkill. A little AlpineJS a little custom JS and you have a usable UI which is rather low tech. Which is maintainable even by non specialists.
@KimHogeling
@KimHogeling 3 месяца назад
I suggest a dedicated controller that parses your data through dedicated views for each client.
@joebazooks
@joebazooks 3 месяца назад
doesnt this make it extremely complicated to create microinteraction animations?
@Vreth6
@Vreth6 3 месяца назад
Then use something else? Use a tool that fits your needs, there is no need to choose only one tool and always use that. Find out what you need to do, and then use an appropriate tool 👍🏻
@MurtagBY
@MurtagBY 3 месяца назад
No, just see the examples on their home page
@KimHogeling
@KimHogeling 3 месяца назад
The build-in animations work fine for our applications. Have a look at hx-transition.
@Bbdu75yg
@Bbdu75yg 3 месяца назад
That derek looks like Dirk Nowitzki !
@naranyala_dev
@naranyala_dev 3 месяца назад
gold
@philliphaydon7017
@philliphaydon7017 3 месяца назад
HTMX is way better than dealing with trash like react/angular.
@miindaugas
@miindaugas 3 месяца назад
Might be because skill issue?
@allyourfuturebelongstochina
@allyourfuturebelongstochina 3 месяца назад
@@miindaugasif it was a skill issue there would be examples of good react apps. But unfortunately there isn’t. Every single one turned into an over abstracted mess that’s difficult to manage.
@_vk03
@_vk03 3 месяца назад
But can you make a webapp like twitch with htmx?? I think No... Whats ur opinion? we dont have advance level of customization in htmx..
@philliphaydon7017
@philliphaydon7017 3 месяца назад
Why can’t you make twitch with htmx? What’s the limits of htmx that make twitch impossible?
@philliphaydon7017
@philliphaydon7017 3 месяца назад
Are you saying no one is skilled with react or angular?
@SnOrfus
@SnOrfus 3 месяца назад
Haven't used it yet, so I don't know if there's some kind of caching layer or something, but it looks like a lot of unnecessary round trips to get, what is effectively, presentation states. That's the first red flag. I also understand that you excluded CSS in the payload markup to simplify the explanation of what's going on here, but there is an implication that there needs to be CSS in the base/original page download that "knows" about the structure/markup of the presentation data that's coming from the api/htmx response. That's seems like some icky coupling and while I admit quite a bit of ignorance here that makes it smell very half-baked.
@KimHogeling
@KimHogeling 3 месяца назад
We use it and regarding your concerns, HTMX respects cache related HTTP headers. We started using tailwindcss, which fixed a huge deal of different css headaches for us. We do have a few more round-trips, but these are smaller and never contain data, that is not needed. (The json data we used to have really were lot's bigger quite often, because the client made the decision, what part of it the user needs..)
@JasonSobell
@JasonSobell Месяц назад
You have to remember that HTMX is not a stack framework, it's a way of extending HTML's hypertext. If you want caching, enable it server side. Likewise with compression, or any other features. As @KimHogeling says, it honours the HTML request standards, and those are controlled server side, so just enable what you want.
@matiascasag
@matiascasag 3 месяца назад
14kb minimized and gzipped... SolidJS is 7kb minimized an gzipped
@Vreth6
@Vreth6 3 месяца назад
Well yeah, but when you start adding your own code - the actual app - the js size increases really quickly. Everything is a tradeoff. SolidJS is awesome and if I was doing something incredibly complex UI wise like a full application I would use something like SolidJS. But if you only do an e-com, an internal tool with some forms etc HTMX is such a breeze to work with.
@verified_tinker1818
@verified_tinker1818 3 месяца назад
14 kb is nothing.
@KimHogeling
@KimHogeling 3 месяца назад
Over time you find yourself using more and more features of HTMX and that's when the few extra KB really pay off. It's actually a really small size for what it can do. And it's just tiny compared to other frameworks. Svelte is also tiny though, but that grows of course with every single new functional feature, just as a side note.
@leftjabrighthook
@leftjabrighthook 3 месяца назад
Need to modify htmx URL's client side? Good luck.
@CodeOpinion
@CodeOpinion 3 месяца назад
Curious why do you need to modify the URLs?
@habsi70
@habsi70 3 месяца назад
What is the use case of changing the URL? That smells of bad design choices.
@dandogamer
@dandogamer 3 месяца назад
What do you mean by modify? Theres various hx attributes that can do this.
@ronaldosd
@ronaldosd 3 месяца назад
But yeah, this should be the last option
@KimHogeling
@KimHogeling 3 месяца назад
For dynamic URLs we use the hx-on:before-request attribute.
@RasmusSchultz
@RasmusSchultz 3 месяца назад
it's just not a good idea. trying to handle UI concerns on the server was not a good idea when we were doing it 20-something years ago, and it's not a good idea now. why are the obvious limitations not mentioned here? if we're being objective, we need to consider the limitations of this approach - you *will* be asked to do something you can't do with this lightweight declarative approach, or at the very least, things you can't do *well* with this approach. we need to consider complexity - you're effectively trying to replace JS with a declarative framework. this framework is likely to grow as users demand more and more of things they were able to do with JS. and how about performance? it's not just the issue that you're sending more (redundant) data, it's also the fact that this data can't be cached like many JSON requests can - or at least can't easily be cached, since cache invalidation would now coupled with HTML, design and layout. You also need to consider the sheer volume of requests, which will be much higher - for something like, say, picking a country and city, where you will need a second request for the list of cities. Every request is more expensive on the server too, since rendering HTML typically involves a template engine, while JSON just requires a simple and usually very fast JSON encoder function. These performance issues can affect user experience as well, because they're making another request after almost every interaction, which will likely feel sluggish - and you can't really optimize UX either by preloading data, because you're not working with data. "oh but React is slow too", yeah, well then use Svelte or Solid or Preact or whatever works better for you - if you want something fast and smooth, learn how to do that. All of these libraries are smaller than HTMX, by the way. Not that the "small" filesize of HTMX is even worth highlighting, since you've just moved all your UI markup out of the client onto to the server and are now sending all of the *rendered* markup with every response. this approach to UI is as unnatural as ever. the natural place to handle user interactions is in front of the user. the only appeal here is for people who hate JS or love their server-side template language - at least be honest then, and just say it, you picked this not because it's technically better in any way, but because you *like* it. And that's fine, but please go into this knowingly - all the same drawbacks we had 20-25 years ago are still there.
@jimiscott
@jimiscott 3 месяца назад
100% - Htmx may be viable for the simplest of sites, but once the complexity and requirements grow then this approach sux. Further, it ignores all the advances the browser has made in the last 20 years and we've gone back to IE 5.5 days.
@Vreth6
@Vreth6 3 месяца назад
This comment is hilarious in so many ways. You manage to be both an old man yelling at clouds and at the same time a naive junior dev who have not yet ran into the issues with modern web dev. Take a deep breath and relax. If you don't like something - don't use it! It is that easy.
@habsi70
@habsi70 3 месяца назад
As an old time dev for me it is the other way around. I am aware that each approach (client vs server side rendering) has its drawbacks. While I appreciate your comment in my experience it is just another approach. And if it isn't the right tool do not use it. We live in a wonderful time where we can choose from so many tools.
@davideastman5806
@davideastman5806 3 месяца назад
I don't see why it needs to be all or nothing for an experienced dev. Anywhere you want to leverage the browser/JS for interactivity instead you can, including having a JSON api, caching strategies, etc. Considering how much the frontend frameworks have moved towards SSR themselves, it seems there are good reasons for both approaches
@depafrom5277
@depafrom5277 3 месяца назад
@@Vreth6 You contributed absolutely nothing to this conversation, your comment reads as if you are the young dev hyped about HTMX :)
@user-qf2xk1fg6e
@user-qf2xk1fg6e 3 месяца назад
Looks interesting, but no. Returning JSON is already kinda a standard. Today you have a browser as a client, tomorrow you have another one type of client that does not work with HTML. And here you go in this case. Use HTML as a data transport because it's comfortable to render in browsers without additional manipulations is an attractive but bad idea.
@deanoldfield5356
@deanoldfield5356 3 месяца назад
But if all you're doing is rendering in browsers that *do* work with Html...
@user-qf2xk1fg6e
@user-qf2xk1fg6e 3 месяца назад
@@deanoldfield5356 today. Tomorrow you need mobile clients.
@neociber24
@neociber24 3 месяца назад
That's what he mentioned at the end. Although I don't think is that different, if you have a service that returns the resource you want to display, moving that service between a HTML view and and API endpoint shouldn't be hard.
@chauchau0825
@chauchau0825 3 месяца назад
No wonder why the whole industry is going downhill as the low barrier is attracting too many midwit that loves prematre optimization
@user-qf2xk1fg6e
@user-qf2xk1fg6e 3 месяца назад
​@@chauchau0825 What?)) Where do you see "prematre optimization" in what I said?) Returning JSON is the simplest and direct way to interact with any web server. I would say the industry is going down because of this new "magic" ways, like: "we go back to 2013 where html response was ok.". In some sense, React was also kinda going back to php/jquery style but with the reactive stuff.
Далее
OpenAPI with a sprinkle ✨ of Hypermedia
6:54
Просмотров 7 тыс.
Keep your project structure simple!
15:08
Просмотров 17 тыс.
Is HTMX a Joke??
32:15
Просмотров 21 тыс.
HTMX Sucks
25:16
Просмотров 122 тыс.
Gitlab DELETING Production Databases | Prime Reacts
17:27
The Simplest Tech Stack
9:38
Просмотров 109 тыс.
Did we learn anything from Microservices? (Part 1)
15:51
r/webdev BANS HTMX??
5:28
Просмотров 149 тыс.
The Truth About HTMX | Prime Reacts
49:56
Просмотров 368 тыс.
Web-Queue-Worker Architecture Style for Scaling
8:47
Creator of HTMX Talks HTMX
1:02:41
Просмотров 178 тыс.
HTMX, the anti JS framework (vs React)
7:17
Просмотров 71 тыс.