fresh-controller-36545
10/06/2021, 10:42 PMHTMX loading events.
This feature is probably meant to be used with "real" pages that return the desired automatically when the link is opened – e.g. http://domain.tld/item/20/. But when HTMX is used to modify/replace a page's single sub-element, it gets quite tricky to restore that internal state without requiring on a complex JavaScript routine to re-initialize it. So I thought maybe there's a way to reinitialize it (semi) automatically by HTMX basically looping through all HTMX elements on the page and triggering the HTMX-element's event if the hx-push-url matches with the current one.user
10/07/2021, 4:49 AMhx-trigger:load after... events not firing if a page was loaded through a Turbolinks <a> tag?
Works great when I do a manual page refresh, but not if I render the page by clicking on a nav link.
Clicking the link while disabling Turbolinks works perfect.billions-microphone-84331
10/07/2021, 7:39 AMhx-boost is presented as a solution to avoid page reloads, to help to implement progressive enhancement, in the same mileage as Turbolinks/Turbo drive. If I understand correctly, "progressive enhancement" means to improve the experience for users when possible, and give a basic experience otherwise. In our context, I guess it means having "no reload" browsing for users having Javascript and regular browsing for others.
With all the "tricks" that I used to make the "no reload" experience work, I am now wondering if my application is still usable without Javascript. For instance, I try to avoid HTTP redirections as they are not really compliant with htmx, but it has the side effect of not redirecting users that don’t have javascript. I could try to preserve the basic experience, but that would mean checking all the time HX-Request, and enhance or not accordingly, but still deliver the "normal" behavior if not present.
I don’t know if you share my opinion on this, but I would like to receive feedback on whether you use hx-boost or not. And if so, do you use it sparingly, or do you try — as me — to have a full "no reload" experience? Htmx is more of a toolbox that gives you low-level primitives to deal with swapping, while apps like Turbolinks (or htmx’s hx-boost) are acting at a higher level, boosting the experience without you (the developer) thinking much about it.
What do you think? Thanks for your feedback.billions-microphone-84331
10/07/2021, 7:39 AMmysterious-toddler-20573
10/07/2021, 10:00 AMturbolinks:load event to initialize htmx using `htmx.process`: https://htmx.org/api/#processmysterious-toddler-20573
10/07/2021, 10:00 AMmysterious-toddler-20573
10/07/2021, 10:01 AMmysterious-toddler-20573
10/07/2021, 10:02 AMhx-boost and let it do its thing, and if there's a spot where it doesn't work well, just turn it off.mysterious-toddler-20573
10/07/2021, 10:03 AMmysterious-toddler-20573
10/07/2021, 10:04 AMmysterious-toddler-20573
10/07/2021, 10:04 AMfresh-controller-36545
10/07/2021, 11:40 AMhx-boost I'd assume you're usually in a situation where you don't have full control about the application. Say the application always returned the full HTML – is it actually possible to take just one part of that response and insert it into the correlating DOM again?
Basically what I'm trying to achieve looks like this – I don't want to reload the whole DOM; just #content.
html
<html>
<head>
<!-- Meta -->
</head>
<body>
<div id="app">
<div id="header" hx-boost="true">
<a href="/path">Reload #content</a>
</div>
<div id="content" hx-swap-oob="innerHTML:#content">
</div>
</div>
</body>
</html>
With /path returning the HTML above.
The documentation states Note that out of band elements must be in the top level of the response, and not children of the top level elements., but doesn't provide further examples – does that mean the scenario doesn't work and in order for it to work you'd have to effectively return two elements as such?
html
<div hx-swap-oob="innerHTML:#elem">
<!-- Content to swap OOB -->
</div>
<div>
<!-- HTMX response for the original request -->
</div>billions-microphone-84331
10/07/2021, 12:18 PMfresh-controller-36545
10/07/2021, 12:22 PM#content from that response?mysterious-toddler-20573
10/07/2021, 12:47 PMlate-king-98305
10/07/2021, 1:25 PMhx-boost and other tricks will work just fine. 🙂
post-redirect-get seems to require a page load (there's no HX-Boosted-Redirect header), so avoiding those does seem to be the best way to avoid page reloads. In this app that I'm migrating, I have all my boosts targeting my main tag, and then the server returns a header that triggers a refresh of the menu portion (with updated "active" CSS classes). Maybe that's more convoluted than just targeting the body tag, but I'm currently still logging on via JS, so this lets me update the menu once the user is authenticated.
The advantage to avoiding a page reload is that the browser doesn't have to parse all the resources for each request (it should have them cached, but it still has to parse them); in most cases, though, that's a micro-optimization that may not have any appreciable usability gains.
TL;DR - It Depends ™ 🙂user
10/07/2021, 2:04 PMmysterious-toddler-20573
10/07/2021, 3:02 PMuser
10/07/2021, 3:04 PMlate-king-98305
10/07/2021, 5:52 PMlate-king-98305
10/07/2021, 5:52 PMgorgeous-airport-54386
10/07/2021, 6:24 PMmysterious-toddler-20573
10/07/2021, 6:41 PMfast-nest-2846
10/07/2021, 10:37 PMmysterious-toddler-20573
10/07/2021, 11:00 PMmysterious-toddler-20573
10/07/2021, 11:01 PMmysterious-toddler-20573
10/07/2021, 11:06 PMmysterious-toddler-20573
10/07/2021, 11:07 PMfast-nest-2846
10/07/2021, 11:11 PMmysterious-toddler-20573
10/07/2021, 11:18 PM