What are the mechanics and implications of swapping the contents of the HEAD tag?
See original GitHub issue(I’m really having a wonderful experience with htmx so far, so thank you.)
My question: what performance implications are there in swapping out the entire contents of the HEAD tag?
In my response from my server, I include a HEAD tag like this:
<head hx-swap-oob="true"> ... contents here ... </head>
This works beautifully – in addition to the other swap, htmx also reaches up and swaps out the contents of the HEAD. (I’ll admit to being shocked. I didn’t expect it to “just work.”)
But does this actually swap the entire inner HTML of the HEAD, and is there a performance penalty there? I feel like doing this would force a reload and recalculation of all the CSS/JS, but perhaps I just don’t understand how that works.
In my…head (ha!), I feel like the contents of the existing HEAD just need to be “reconciled” against the contents of the new HEAD, and some changes need to be made – usually just the TITLE and some META. Ideally, the smallest number of changes would be made to make the existing HEAD match the incoming HEAD.
So, two questions:
- How does htmx swap out the
HEAD? I’m watching in inspector, and I just see theTITLEtag change, but that might just be how the inspector UI works – it only highlights what changes, even though the entire inner HTML was swapped. - If I did want more selectively swapping, would the morphdom extension be the right way to do this?
- If morphdom is the right way to do, where to I put the
hx-ext="morphdom-swap"andhx-swap="morphdom"attributes? On theMAINelement (where thehx-boostattribute is) or on theHEAD(and which one – the original, or the incoming)?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)

Top Related StackOverflow Question
This approach is seemingly working out well for myself. I’m returning this in the swap:
<title id="pageTitle" hx-swap-oob="true">Contact</title>Seems like a new event here would be ideal for this:
https://github.com/bigskysoftware/htmx/blob/fda4957d653ebf683d6017c07a6ef34ed2d72983/src/htmx.js#L136