News for hackers. Stuff that matters.
Re:Htmx by zelphirkalt on Wednesday December 14, 2022 @02:45PM (#33989116)
But HTMX is a JS library. Anything done with it is basically done with JS.
Re:Htmx by drdaeman on Wednesday December 14, 2022 @03:18PM (#33989784)
I'd say it's not about what can be done, it's about how it's defined. HTMX is a abstraction layer on top of an existing abstractions that you still have to know, because it's defined in terms of those abstractions.

So when you write something like `hx-trigger="click" hx-put="/api/my"` you're actually actively thinking of an `addEventListener("click", ...)`, `this.innerHTML` assignment and `fetch("/api/my", { method: "PUT" }))`. Can't use HTMX without knowing the underlying principles and primitives.

And then you still have to do JS because how else you're supposed to handle `htmx:responseError` and stuff. And maybe I'm wrong but it feels risky because the logic could end up all around the place and not in a single nice function/code block.

So, basically, it's a nice DSL providing a bunch of shortcuts, but it doesn't magically alleviate knowing any underlying principles and nuances of JS and DOM. Again, it's even defined in terms of those systems (`hx-swap="outerHTML"` being a very clear indicator example).

Re:Htmx by mirekrusin on Wednesday December 14, 2022 @02:49PM (#33989170)
Kernel is done with C. Everything is basically done with C. Even JavaScript.
Re:Htmx by hirvi74 on Wednesday December 14, 2022 @02:56PM (#33989320)
It's all binary at the end of the day.
Re:Htmx by nudpiedo on Wednesday December 14, 2022 @03:15PM (#33989707)
It’s all just energy moving around
Re:Htmx by dunno7456 on Wednesday December 14, 2022 @03:22PM (#33989872)
On sand.
Re:Htmx by I_complete_me on Wednesday December 14, 2022 @04:13PM (#33990667)
And those turtles that go all the way down lay their eggs in that sand.
Re:Htmx by zelphirkalt on Wednesday December 14, 2022 @02:51PM (#33989205)
That doesn't address the implications of something only working with JS at all.
Re:Htmx by TechBro8615 on Wednesday December 14, 2022 @05:10PM (#33991343)
The most popular JavaScript engine (V8) is written mostly in C++. Same with WebKit. Other JS engines are written in Rust, like Deno or Servo (used in parts of Firefox).

I'm not aware of a major Javascript engine which is written in C, except for QuickJS, which is not "major" in any sense of popularity but is an efficient engine for embedded use cases (and anything from Fabrice Bellard is always work a look).

Re:Htmx by aabbcc1241 on Saturday December 17, 2022 @03:59AM (#34026109)
I suppose C++ is written in C. In similar relationships like Typescript and Javascript.
Re:Htmx by detaro on Saturday December 17, 2022 @04:02AM (#34026122)
Not really, no.
Re:Htmx by theptip on Wednesday December 14, 2022 @03:12PM (#33989650)
The point you're missing here is that if you use HTMX, you often don't need to write any JS. You just write HTML with some special tags, and the library handles everything for you.
Re:Htmx by drdaeman on Wednesday December 14, 2022 @05:40PM (#33991743)
Spoiler warning: it doesn't.

Unless you only consider the happiest path, as in "I develop on localhost with zero latency, 100% uptime, and my backend validation logic perfectly matches my frontend policies" (and probably a lot more other "if"s and "only"s).

Re:Htmx by sandGorgon on Thursday December 15, 2022 @01:45AM (#33996132)
this is an interesting comment. so it has been sold to me like that. Could you talk about where it fails.

alpinejs does make the claim that it is a "better jquery". What is the development experience here?

especially for backend teams (python, java, whatever) who are now also building HTMX.

Re:Htmx by adamckay on Thursday December 15, 2022 @06:57AM (#33998176)
> Could you talk about where it fails

If the HTTP request that htmx has made returns a status code >= 400 or times out then the response will not be swapped into the body.

There are several events that htmx fires, once of which can catch `responseError` [1] and you can write some Javascript to handle it according to your requirements (throw a toast, swap anyway by setting `evt.detail.shouldSwap = true`.

In a project I'm working on we use htmx to load the content for modals, so we have small handlers on htmx events to display the modal whilst the request is being made, put a spinner indicator in the modal body to show the user something is happening and then swap the body in once the request has completed.

We've also used `HX-Trigger` response header [2] which htmx helpfully catches and allows us to easily hook onto, we've got ones to display a toast notification, hide open modals, refresh content divs, untick bulk action checkboxes, etc.

All in, our project probably has around 200 lines of Javascript for the different event handlers we do, so it doesn't eliminate the need to write any JS, but it's significantly reduced and is pretty much all event handlers.

1 - https://htmx.org/events/#htmx:responseError

2 - https://htmx.org/headers/hx-trigger/

Re:Htmx by sandGorgon on Thursday December 15, 2022 @07:42AM (#33998624)
this was super duper useful!

so would you say that one of the first things a htmx based project should do is handle all the error conditions ? like all the 40x and 50x ? and stuff like your modal thinggy ?

how do you develop the js here ? do you setup a different nodejs/npmjs toolchain. or do the jqueryish development of edit->browser reload ?

Re:Htmx by adamckay on Thursday December 15, 2022 @11:14AM (#34001706)
> so would you say that one of the first things a htmx based project should do is handle all the error conditions ? like all the 40x and 50x ? and stuff like your modal thinggy ?

IMO yeah, but different pages and actions will (probably) want different things. For example clicking a button that makes a POST request may make more sense to have a red toast notification if it fails, however a tab that dynamically loads its content in using htmx might want a dummy placeholder saying "Sorry, try again later" or something like that. Functionality around the modals were done as and when we needed them and then expanded on over time so I don't think you need to write/know everything up front. It's honestly been a joy to use based on how simple it is once embrace server side rendering.

> how do you develop the js here ? do you setup a different nodejs/npmjs toolchain. or do the jqueryish development of edit->browser reload ?

For my projects it's just 1 or 2 JS files that are included in my base template that contain the event handlers, so it's quite old school of edit and refresh. I use Django mostly now so I can use that to collect and minify static files so it's low effort/complexity.

The only down side is for the few JS packages I do need (e.g. Select2 for nice dropdowns) I either vendor the package in (no automatic updates) or use NPM (but it's a pain). Again, depends on what you want because htmx doesn't care either way.

Re:Htmx by vagrantJin on Thursday December 15, 2022 @07:15AM (#33998342)
+100 for alpinejs.

Alpinejs is indeed the successor to Jquery.

React forces you to think like how its designers view the world.

While alpinejs does not really interfere with your workflow. That's a huge sell for team like mine where we are working with legacy projects and devs of various levels of XP. We can get a jnr dev up and running in a week flat.

Re:Htmx by sandGorgon on Thursday December 15, 2022 @07:44AM (#33998639)
hey thanks for that. any particular opinions on hyperscript vs alpinejs ?

hyperscript is said to be "made for htmx". But alpinejs is generally more popular standalone. so im wondering about the choices here if we're starting a htmx project.

Re:Htmx by vagrantJin on Monday December 19, 2022 @06:49AM (#34051048)
Sorry mate. Have not used hyperscript so any comparison from me would be less than objective.
Re:Htmx by todotask on Wednesday December 14, 2022 @09:58PM (#33994572)
Accessibility requires work with JavaScript.
Re:Htmx by naasking on Thursday December 15, 2022 @09:03PM (#34008670)
What accessibility requires more than aria tags on your content?
Re:Htmx by devmunchies on Wednesday December 14, 2022 @05:24PM (#33991534)
It’s almost like htmx is a byte code target that you feed to the htmx JavaScript library. It’s easy to generate htmx markup with any backend language.

So instead of a backend language transpiling to JavaScript (like clojurescript), I can just generate htmx markup.

Re:Htmx by ksec on Thursday December 15, 2022 @09:46AM (#34000274)
Well, I hope someday HTMX will be HTML6.