https://htmx.org logo
You're experiencing intentional behavior; one of t...
# htmx-general
l
You're experiencing intentional behavior; one of the things that makes
hx-boost="true"
speed things up so much is that it doesn't reload the
head
(it will pull out the
title
and replace that). All the scripts and styles remain, so you're really just swapping out the body. (There was a whole discussion about this in this channel over the past weekend, but it was really in-the-weeds.) That's why I recommended moving the script out to an external file, and referencing that in the
head
. It'll initialize the first time, but it won't reinitialize every time. There are a few other ways, but if you're looking for the most straightforward, that would be it. Think about it like this; the typical HTTP request/response transaction is stateless. However, to avoid swapping out the entire page, htmx introduces state in the current browser session. Because of this, you will want to put its initialization, or your custom initialization, outside the part of the page that's being replaced. `script`s in the replaced content will be loaded and executed, which is what you're seeing here. (There are use cases where this behavior is desired.) I hope that makes sense.