htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Disable boosting for non text/html responses

Open iacore opened this issue 6 months ago • 1 comments

If I click on the link below, the page is rendered by placing the PNG data into the HTML page.

<body hx-boost="true">
  <a href="image.png">Image</a>
</body>

It shouldn't be like this. HTMX should go to that URL instead.

iacore avatar Jun 05 '25 04:06 iacore

Unfortunately this is not how hx-boost is meant to work. hx-boost when set to true will make all links and forms into htmx actions that replace the body of the page. They are not designed to be used with all types of links and actions and it is important when applying hx-boost to the whole page via the body tag that you also set hx-boost="false" on any elements you want to function like normal links instead of using htmx boosting behavior. hx-boost is not designed to be a silver bullet that magically works for everything.

<body hx-boost="true">
  <a hx-boost="false" href="image.png">Image</a>
</body>

There is no way for htmx to know the content type of the link before you click it and initiate a htmx boost request. And once the action is completed there is no practical way to detect the content type of the response and perform some alternative action. Web servers do not consistently return an accurate Content-Type which is why browsers currently sniff the content type of the returned content to make the decision on how to render it. So it is up to the developer of the page to make the decision on which links to apply hx-boost to.

Also I'm not sure it is a valid web design choice to try implementing a htmx application with links to same-site hosted images that you want to break out of your application and render an image full frame directly. The point of using hx-boost is to allow simple multi page web apps to work with htmx and the act of rendering an image should ideally be its own page in your application with something wrapping the image. Note image links that are not local/relative paths and instead link to external sites are always treated as normal links.

MichaelWest22 avatar Jun 09 '25 22:06 MichaelWest22

Can be closed I think?

yawaramin avatar Jul 20 '25 15:07 yawaramin

mmm ok. Thanks for the explanation!

iacore avatar Jul 23 '25 06:07 iacore