htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Duplicated requests when leaving page with `hx-boost`

Open GaelGirodon opened this issue 1 year ago • 0 comments

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.php and page2.php, multiple times, with JS/htmx enabled, then disabled

Actual

  • With JS/htmx: a request to stream.php is issued each time (when navigating to and from page1.php), even if only page1.php has the <img> tag ❌

with htmx

  • Without JS/htmx: the request to stream.php is only issued when navigating to page1.php ✔️

without htmx

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!

GaelGirodon avatar Jun 15 '24 19:06 GaelGirodon