Skip to content

[4.0.0-beta6] hx-preload fails to reuse cached GET when hx-get uses relative URLs #3948

Description

@woutergrimme

Bug report

Using htmx 4.0.0-beta6 with the hx-preload extension.

When preloading a link with a relative hx-get URL, the preload request is made successfully, but the cached response is not reused on click.

Example:

<a
    hx-get="https://domain.com/some/url"
    hx-preload="mouseover timeout:10s">
    Some link
</a>

Steps to reproduce:
Hover the link.
Wait for the preload request to complete.
Click the link.

Expected:
The click should reuse the preloaded response.

Actual:
A second GET request is sent.

Debugging showed:

cached action : https://domain.com/some/url
current action: /some/url

The comparison in hx-preload.js:

elt._htmx.preload.action === ctx.request.action

This fails because the URLs are semantically identical but different strings.

A possible fix (tested locally):

elt._htmx.preload.action === new URL(ctx.request.action, location.href).href

This normalizes the URL before comparison.

Environment:

htmx: 4.0.0-beta6
hx-preload: 4.0.0-beta6
Browser: Chrome/Firefox

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions