bigskysoftware / bigskysoftware/htmx

Duplicated requests when leaving page with `hx-boost`

Open
#2,618 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

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](https://gist.github.com/GaelGirodon/8ba17790f1b1db412e2d99fa8f806357)
- Start a local PHP development server: `php -S localhost:8000`
- Open
- 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 `` tag ❌

![with htmx](https://github.com/bigskysoftware/htmx/assets/10748287/ca7ec6a1-7fbb-43ca-a659-6459a6c0933f)

- _Without JS/htmx_: the request to `stream.php` is only issued when navigating to `page1.php` ✔️

![without htmx](https://github.com/bigskysoftware/htmx/assets/10748287/bc9050d6-df8c-481f-b450-43d72a6cdba8)

**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 `` 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!

Contributor guide

Open the contributing guide

Research direction

Get the reproduction files from the linked Gist, then run `php -S localhost:8000` and compare navigation between page1.php and page2.php in the network inspector with htmx enabled and disabled. Focus on why stream.php is requested when leaving page1.php; done means navigation with hx-boost produces no additional stream.php request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.