Skip to content

Add hx-boost to header nav #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

Jer-Pha
Copy link
Contributor

@Jer-Pha Jer-Pha commented Jun 26, 2024

This is a very small optimization using hx-boost.

Instead of navigating to a new page, internal links will use an AJAX request and replace the current page in place. The previous page is added to the browser's history and can still be navigated to using the back button. The docs mention the <body> tag, but it actually replaces all html.

@davidfischer
Copy link
Member

I may have to do a bit more research on this but my general opinion is pretty skeptical of this change. The gains seem a bit marginal since it still requests the full page but just replaces the body tag. Seems like added complexity for small if any gains unless I'm missing something.

@Jer-Pha
Copy link
Contributor Author

Jer-Pha commented Jun 28, 2024

It's more of an improvement for UI/UX. It's not exactly measurable but links "feel" better to me when clicked. It's hard to explain. Definitely not necessary, just a small change I came across while working with htmx.

@Jer-Pha
Copy link
Contributor Author

Jer-Pha commented Jul 13, 2024

The more I experiment with hx-boost, the less I like it. Closing this.

@Jer-Pha Jer-Pha closed this Jul 13, 2024
@davidfischer
Copy link
Member

What didn't you like about it?

@Jer-Pha
Copy link
Contributor Author

Jer-Pha commented Jul 13, 2024

The main issue I ran into is the new page loading below the current page, instead of replacing it. This would usually happen if the link was populated from another htmx request. My solution was to add hx-boost="false" to the parent of these links. This was happening with hx-boost enabled on the navbar div, not <body>.

I also found that it does not carry over classes attached to the body. I have a page that doesn't extend base.html. When linking to a page that did extend the base template, the base template's classes on <body> did not load. This is actually why I removed it from my project. I'm concerned that it might not be consistent with html outside of <body>, and I don't want to risk <body> <head> or <html> having issues.

I do really like how it feels. I haven't removed it from EB yet, if you want to check it out. Having the header stay consistent without "blinking" is really nice. I'm just not sure that is worth the potential risk of missing info outside of the body.

@Jer-Pha
Copy link
Contributor Author

Jer-Pha commented Jul 13, 2024

The smoothness (e.g. no "blinking") isn't really noticeable unless you throttle the connection. So hx-boost seems to be more beneficial for users with slower connections. They are probably used to pages loading slower, though.

@Jer-Pha Jer-Pha deleted the hx-boost branch September 27, 2024 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants