Htmx response headers: HX-Reselect

Lazarus:

So our next response header here is achecks reselect. So this is similar to retarget and reswap. These are all response headers that override their sort of sister attributes, which you may be more familiar with, like h x target, h x swap, and in this case, h x select. So if you're used to using the h x select attribute, then this just lets you override it. Just as a refresher, what is the h x select attribute?

Lazarus:

It lets you choose from your full HTML that gets returned, by the request which parts will be selected from that. So it's like a filter, and you can just filter out, using a css selector. You might have a route that returns the full HTML or just more HTML than you than you need, but maybe you don't want to create a new route with a new endpoint. You know, maybe you just want to use that same end point for a few different things and then just pull out the ID that you need to place it where you want on the page. And, you know, like I said, this uses the CSS selectors, so you can, you know, let's take for an example, just pull out that one ID.

Lazarus:

Or you could get, you know, an the first item on a list, you could get a bunch of different possibilities. I think you can do it by class, but it will take only the first thing in the class, so it's not gonna, like, take all the items in the class if you use a class. So reselect is lets you do the same thing, but from your response header. So this, you know, hx reselect is a response header, you send that response back to an HTML request and that lets you add or override the select that's already there, the hx select that's already on there, or if there's not one there it lets you add it. So, like I said, this uses, you can use this combo of swap, select, and target.

Lazarus:

These are sort of, 3 of the sort of attribute overrides that are included in these responses. And these are kind of the 3, 3 of the most the ones you'll use the most. Right? For for swapping, lets you says how you're gonna swap the HTML out, select lets you filter that HTML, and target lets you say where it's gonna go. So between those three things you have a lot of control.

Lazarus:

You can really tap into the full power of HTMLX right from your response headers, so you don't necessarily need to be putting every time the attributes on there, or you can override the attributes afterwards, if you have some use case where, it's more useful to decide this from the server and put that into your response header. And again, this is something you may never need to do, but, as we saw on Twitter this week, and there was a big disargument or discussions of hypermedia friend Hotwire, you know, DHH is a hypermedia kind of like has his own Hotwire thing, and he's been building they've been 37 signals have been building a bunch of stuff. There was a big kerfuffle this week about is hypermedia, you know, is is this format sending HTML over the wire? Is this too slow? So, you know, some there was kind of this back and forth argument, And my takeaway from all that is that people are building all kinds of stuff using all kinds of crazy tech, and good for them, HTMX is just more of the same.

Lazarus:

You can build cool stuff using this crazy tech. This just happens to be the crazy tech that you like, or at least the one that you're learning about. It's the one that I am learning about, the one that I like. So I say step up, do some crazy shit with it, and use these response headers as much as you want. You know, if you can find some amazing use for these response headers, that people haven't thought of before, and let you, you know, give you some ability, some power that you've never had before that just kind of is interesting.

Lazarus:

You know, that's what it's all about. You can figure this stuff out, find something useful to do with it. The deeper you go into it, the cooler stuff you can do. So, yeah, I say go for it.

Htmx response headers: HX-Reselect
Broadcast by