HTMX: What's Old is New Again

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 114

  • @KimHogeling
    @KimHogeling 6 หลายเดือนก่อน +17

    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 5 หลายเดือนก่อน

      "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 6 หลายเดือนก่อน +19

    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  6 หลายเดือนก่อน +2

      Exactly

  • @ShawnThuris
    @ShawnThuris 6 หลายเดือนก่อน +4

    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 5 หลายเดือนก่อน +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 6 หลายเดือนก่อน +5

    Used it a couple weeks ago to make a small internal admin site, it was great fun

  • @capability-snob
    @capability-snob 6 หลายเดือนก่อน +1

    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.

  • @BTFranklin
    @BTFranklin 6 หลายเดือนก่อน +3

    I appreciate this kind of thoughtful analysis, delivered in a straightforward and time-efficient format. Thank you!

  • @falldowngoboone
    @falldowngoboone 6 หลายเดือนก่อน +10

    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 6 หลายเดือนก่อน

      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  6 หลายเดือนก่อน +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 6 หลายเดือนก่อน

    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 6 หลายเดือนก่อน +5

    HTMX absolutely rocks.

  • @byangas
    @byangas 2 หลายเดือนก่อน

    I have written dozens and dozens of APIs and web and mobile clients. I would say that in my experience with attempting to do performance improvements on these projects that the size of data returned in an API call is the most significant factor that affects performance. One of the issues I see with the pattern shown here is that the size of the data being returned by the "server side rendering" of HTMX would potentially be an issue with scaling. SPAs became popular for a reason, and part of that was to limit the amount of data being sent across the wire. A well designed web application should be pulling down only the data it needs to render to the user. Having a web/API call that returns nearly identical content, except for the critical data, is something I would be cautious about implementing. Having a SPA with a template that calls out to an API and pulls just the data it needs to render to the user would be my preferred implementation. Also, in the example he shows where the REST API is returning "links" section is something I would never implement. The whole HATEOS concept never made sense to me and adds bloat to API calls that is not needed. I think that HTMX as shown in this video would work for smaller scale applications where the speed of development is important, but would quickly fall down on a system that experienced millions of requests a day.

  • @margosdesarian
    @margosdesarian 6 หลายเดือนก่อน

    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 5 หลายเดือนก่อน

    This reminds me of the old Nitobi components, where it used declarative html Ajax widgets.

  • @fennecbesixdouze1794
    @fennecbesixdouze1794 5 หลายเดือนก่อน

    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 4 หลายเดือนก่อน +1

      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.

  • @Kekszmester
    @Kekszmester 3 หลายเดือนก่อน

    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  2 หลายเดือนก่อน +1

      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"

  • @CodeCraftHub-NAS
    @CodeCraftHub-NAS 5 หลายเดือนก่อน

    You mentioned ColdFusion and got a subscription for this Old Guy!

    • @CodeOpinion
      @CodeOpinion  5 หลายเดือนก่อน

      welcome to the old guy club!

    • @CodeCraftHub-NAS
      @CodeCraftHub-NAS 5 หลายเดือนก่อน

      @@CodeOpinion I started ColdFusion back in 1996 so I feel looking at your photo I might be older. LOL

    • @CodeOpinion
      @CodeOpinion  5 หลายเดือนก่อน

      I was writing perl in a cgi-bin at that time. I'm older than I look I guess 🤣

    • @CodeCraftHub-NAS
      @CodeCraftHub-NAS 5 หลายเดือนก่อน

      @@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...

  • @AdamsTaiwan
    @AdamsTaiwan 23 วันที่ผ่านมา

    I never did follow the rules. I always post to a method an return a .net object which can be any structure data or html. Our sites are only for in-house use.

  • @kublaios
    @kublaios 6 หลายเดือนก่อน

    Very well explained, thank you.

  • @jbeaudoin11
    @jbeaudoin11 6 หลายเดือนก่อน +1

    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 6 หลายเดือนก่อน +1

      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 6 หลายเดือนก่อน

      ​@@ronaldosd looks like a nice stack, at first glance anyway.

    • @jbeaudoin11
      @jbeaudoin11 6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน

      I use FastAPI but I just use string formatting instead of jinja2 for creating my HTML templates.

  • @philliphaydon7017
    @philliphaydon7017 6 หลายเดือนก่อน +3

    HTMX is way better than dealing with trash like react/angular.

    • @miindaugas
      @miindaugas 5 หลายเดือนก่อน

      Might be because skill issue?

    • @allyourfuturebelongstochina
      @allyourfuturebelongstochina 5 หลายเดือนก่อน

      @@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 5 หลายเดือนก่อน

      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 5 หลายเดือนก่อน

      Why can’t you make twitch with htmx? What’s the limits of htmx that make twitch impossible?

    • @philliphaydon7017
      @philliphaydon7017 5 หลายเดือนก่อน

      Are you saying no one is skilled with react or angular?

  • @TomEugelink
    @TomEugelink 6 หลายเดือนก่อน +2

    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 6 หลายเดือนก่อน

      You obviously don't get it. All state is on the server where it belongs.

    • @TomEugelink
      @TomEugelink 6 หลายเดือนก่อน +1

      @@AndersBaumann I don't get it? Okay. 😆

    • @habsi70
      @habsi70 6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน +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 6 หลายเดือนก่อน

      @@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.

  • @purezero23
    @purezero23 6 หลายเดือนก่อน

    What if I have two clients that both use htmx but want the edit forms displayed differently?

    • @habsi70
      @habsi70 6 หลายเดือนก่อน +1

      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 6 หลายเดือนก่อน +1

      ​@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 6 หลายเดือนก่อน

      @@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 6 หลายเดือนก่อน

      I suggest a dedicated controller that parses your data through dedicated views for each client.

  • @zonegamma8197
    @zonegamma8197 5 หลายเดือนก่อน

    Good video thanks

  • @joebazooks
    @joebazooks 6 หลายเดือนก่อน +1

    doesnt this make it extremely complicated to create microinteraction animations?

    • @Vreth6
      @Vreth6 6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน +1

      No, just see the examples on their home page

    • @KimHogeling
      @KimHogeling 6 หลายเดือนก่อน +1

      The build-in animations work fine for our applications. Have a look at hx-transition.

  • @Bbdu75yg
    @Bbdu75yg 6 หลายเดือนก่อน

    That derek looks like Dirk Nowitzki !

  • @naranyala_dev
    @naranyala_dev 5 หลายเดือนก่อน

    gold

  • @SnOrfus
    @SnOrfus 6 หลายเดือนก่อน

    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 6 หลายเดือนก่อน +1

      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 4 หลายเดือนก่อน

      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 6 หลายเดือนก่อน +3

    14kb minimized and gzipped... SolidJS is 7kb minimized an gzipped

    • @Vreth6
      @Vreth6 6 หลายเดือนก่อน +4

      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 6 หลายเดือนก่อน +5

      14 kb is nothing.

    • @KimHogeling
      @KimHogeling 6 หลายเดือนก่อน +1

      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 6 หลายเดือนก่อน +1

    Need to modify htmx URL's client side? Good luck.

    • @CodeOpinion
      @CodeOpinion  6 หลายเดือนก่อน +8

      Curious why do you need to modify the URLs?

    • @habsi70
      @habsi70 6 หลายเดือนก่อน +3

      What is the use case of changing the URL? That smells of bad design choices.

    • @dandogamer
      @dandogamer 6 หลายเดือนก่อน

      What do you mean by modify? Theres various hx attributes that can do this.

    • @ronaldosd
      @ronaldosd 6 หลายเดือนก่อน

      But yeah, this should be the last option

    • @KimHogeling
      @KimHogeling 6 หลายเดือนก่อน

      For dynamic URLs we use the hx-on:before-request attribute.

  • @RasmusSchultz
    @RasmusSchultz 6 หลายเดือนก่อน +5

    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 6 หลายเดือนก่อน +2

      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 6 หลายเดือนก่อน +5

      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 6 หลายเดือนก่อน +4

      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 6 หลายเดือนก่อน +5

      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 6 หลายเดือนก่อน +1

      @@Vreth6 You contributed absolutely nothing to this conversation, your comment reads as if you are the young dev hyped about HTMX :)

  • @ИванИванов-я5э9к
    @ИванИванов-я5э9к 6 หลายเดือนก่อน +4

    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 6 หลายเดือนก่อน +17

      But if all you're doing is rendering in browsers that *do* work with Html...

    • @ИванИванов-я5э9к
      @ИванИванов-я5э9к 6 หลายเดือนก่อน

      @@deanoldfield5356 today. Tomorrow you need mobile clients.

    • @neociber24
      @neociber24 6 หลายเดือนก่อน +5

      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 6 หลายเดือนก่อน +4

      No wonder why the whole industry is going downhill as the low barrier is attracting too many midwit that loves prematre optimization

    • @ИванИванов-я5э9к
      @ИванИванов-я5э9к 6 หลายเดือนก่อน

      ​@@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.