Hacker News new | ask | show | jobs
by recursivedoubts 894 days ago
hey there, I'm the creator of htmx, and I really appreciate you making this! very cool!
4 comments

Thankyou for the awesome library! I have a question.

Is there a way to use HTMX with minimal server side changes. Specifically if I have an existing page that you fill in a form and submit and response is of course the entire page. I think it would be cool to tell htmx that the whole page is being returned BUT I only want to update #my-form and that way you don’t need any “if htmx request” kinda stuff on the server.

This is for people who care about their site working without JS. But also it allows you to have a single backend endpoint to handle multiple things (for example comments, sign up to email, like button, all in one)

If I understood correctly, you can achive this with `hx-target` and `hx-select` - I'm doing this in an app to replace an editor content based on which link is clicked.

- https://htmx.org/attributes/hx-select/ - https://htmx.org/attributes/hx-target/

Oh that's neat - so you can return more than htmx will use and it can select the element it needs in the response and discard the rest
Yep, I actually don't even do server side checks in my app I am building, I just hx-boost on my html element and then server side I redirect back to the page that should have the updated content, just like you would a traditional server rendered app, and htmx then swaps out the body, but if I use target and that I can tell it to only return say the `<main>` tag and maybe another part of the page, the rest doesn't change.
That could be it! I missed that one. Will try it next time.
I'm not sure about HTMX, but this kind of behaviour is what Unpoly https://unpoly.com/ excels at

I played with it recently and it was pretty easy to enhance a completely non-js CRUD type app and have it fall-back gracefully. Seems a similar concept to HTMX but has a more batteries included / high-level approach.

I'm in the early stages of an Unpoly project and I'm happy with it so far. It's nice to have things built-in like modals and attaching data & logic to incoming elements. Feels like I have less need to integrate with Alpine.
in addition to the other tools mentioned in sibling comments, there is a multi-swap extension:

https://htmx.org/extensions/multi-swap/

hx-boost is the simplest way to do this, but it updates the body content rather than the form. In most cases this will probably be effectively the same.
hx-target="closest <your element here>" hx-swap="outerHTML swap:1s" hx-push-url="false"

That'll return whatever partial thing you want to return and replace <your element here> (with 1sec effect).

Likewise man. In the face of avoiding JS, I think we've both taken one for the team here
> In the face of avoiding JS, I think we've both taken one for the team here

In which, you still need to include a JS file. I'd still count that as Javascript.

Pretty clear that they mean "avoid writing javascript," not "avoid executing javascript"
Now that you mentioned it, its clear. However I didn't interpret originally it that way.
Wait til you find out I'm using htmx with node.
Me when I buy a face mask and immediately ask people to spit in my eyes
based
Wait til he finds out what htmx is built with.
As a CEO of htmx, I second this appreciation. Well done!
Haven’t tried htmx. Have you heard of phoenix liveview? Are they similar concepts?
htmx is lower level than the various liveview implementations

this makes htmx more work, in general, to accomplish things but also less opaque

htmx is laser focused on generalizing hypermedia controls in HTML (anchors & forms)