htmx
htmx copied to clipboard
Duplicated requests when leaving page with `hx-boost`
Some requests issued when navigating to a page (e.g. getting an image) are issued again when leaving the page by clicking on a link to navigate to another page, using hx-boost.
Steps to reproduce
- Get the files from this Gist
- Start a local PHP development server:
php -S localhost:8000 - Open http://localhost:8000/page1.php
- Open the network inspector
- Navigate between
page1.phpandpage2.php, multiple times, with JS/htmx enabled, then disabled
Actual
- With JS/htmx: a request to
stream.phpis issued each time (when navigating to and frompage1.php), even if onlypage1.phphas the<img>tag ❌
- Without JS/htmx: the request to
stream.phpis only issued when navigating topage1.php✔️
Expected
The request to stream.php should only be issued when navigating to (and not from) page1.php, in both cases.
➡️ Using hx-boost shouldn't trigger additional requests. Does htmx DOM manipulation is responsible for triggering these requests? On pages with many resources (multiple <img> elements), this can lead to a lot of useless additional requests to be sent. Can we prevent this?
Some more things I've tested
- Disabling the cache doesn't seem to solve the problem (
historyCacheSize = 0,historyEnabled = false) - Using
@hotwired/turbo(instead of htmx +hx-boost), with prefetch disabled (turbo-prefetch=false):- With cache enabled (default): the same issue happens
- With cache disabled (
turbo-cache-control=no-cache): the issue disappears
Environment
- htmx: 1.9.12 (from CDN or from NPM + bundled using Vite)
- Browser: Firefox 127, Chrome 125
- Backend: Go/Echo, PHP
- OS: Windows 11
PS: thanks for this great library!