billions-microphone-84331
09/16/2021, 12:39 PMhx-boost attribute directly on the body tag? (sorry if the question sounds absurd, it is just that i haven’t grasp exactly yet how hx-boost was operating)billions-microphone-84331
09/16/2021, 1:38 PMhx-boost to better understand, but does hx-boost always replace <body> or does it take the closest hx-target into account instead of <body> when available?billions-microphone-84331
09/16/2021, 2:01 PMbillions-microphone-84331
09/16/2021, 2:22 PMhx-target is not defined, because the body becomes the target), instead of the full HTML page.
But you say also that "by accident", the parsing of HTML will ignore all the non-body stuff. Hence it would "fall in place" even if the server returns the whole page instead of the body right?
I think this information could be added to the docs so that people know how to deal with boosted requests on the server. Like should they have two different endpoints for boosted vs non-boosted requests for the same resource, or should they have a templating logic to include only the body vs the full page?
To me, hx-boost really starts to make sense if the server does not have to do anything special in returns. It would allow being really close to what turbolink provides, by continuing to return full responses on the server and see the magic happens on the frontend (and have a nice fallback to plain page reloads when js is disabled).little-greece-16394
09/16/2021, 2:26 PMlittle-greece-16394
09/16/2021, 2:26 PM<body> contents will be used (and the whole body replaced)little-greece-16394
09/16/2021, 2:27 PMbillions-microphone-84331
09/16/2021, 2:28 PMlittle-greece-16394
09/16/2021, 2:28 PMlittle-greece-16394
09/16/2021, 2:29 PMbillions-microphone-84331
09/16/2021, 2:33 PM/contacts - returns the UI for all contacts, may check for HX-Request header to render without a layout
So even if it is a feature, he recommends having a check on the HX-Request to render with or without the layout, while this might not be necessary as the behavior would be the same if always returning the layout included version.
And yes, it is kinda documented in https://htmx.org/docs/#boosting but maybe there should be a little more precision on what the server is expected to return (telling explicitly that a full page can be returned, and not only the body).little-greece-16394
09/16/2021, 2:34 PM<body> but just e.g. the <div> with the contacts in and an approriate hx-targetlittle-greece-16394
09/16/2021, 2:34 PMbillions-microphone-84331
09/16/2021, 2:38 PM/contacts would never return a full HTML page at all, and so would only be used for htmx ajax requests (and not for regular browser requests).little-greece-16394
09/16/2021, 2:39 PMbodybillions-microphone-84331
09/16/2021, 2:43 PMmysterious-toddler-20573
09/16/2021, 4:03 PMHX-Request header and only return the content, rather than the html head, etc. Ideally this can be done in a generic filter, as with rails.
With respect to the target of boosting, the default is the body. However, you can override this by placing an hx-target attribute in a parent element of the DOM for links. Sometimes you have a situation where you have an inner UI (a div) that uses its own target, and then you must "reset" the target of boosted links in that div to body:
html
<body hx-boost="true">
...
<div hx-post="/whatever" hx-target="this">
...
<a hx-target="body" href="/foo"> ... </a>
</div>
</body>mysterious-toddler-20573
09/16/2021, 4:04 PMmysterious-toddler-20573
09/16/2021, 4:04 PMmysterious-toddler-20573
09/16/2021, 4:04 PMbillions-microphone-84331
09/16/2021, 4:07 PMbody tag, or a more precise scoped div around the central "component" of the page?billions-microphone-84331
09/16/2021, 4:08 PMdiv containing the list of contacts to go back to your example)mysterious-toddler-20573
09/16/2021, 4:10 PMhtml
<html>
<head>
...
</head>
<body>
THE CONTENT
</body>
</html>mysterious-toddler-20573
09/16/2021, 4:11 PMmysterious-toddler-20573
09/16/2021, 4:11 PMmysterious-toddler-20573
09/16/2021, 4:11 PMhtml
<html>
<head>
...
</head>
<body>
{{content}}
</body>
</html>mysterious-toddler-20573
09/16/2021, 4:12 PMmysterious-toddler-20573
09/16/2021, 4:12 PMruby
render layout:nonemysterious-toddler-20573
09/16/2021, 4:12 PMmysterious-toddler-20573
09/16/2021, 4:12 PM