Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preload: added a "hx-preload" header to hx-get and href requests #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bogdano
Copy link

@bogdano bogdano commented Jul 24, 2024

Also added hx-request header to href preload requests, in case implementations rely on hx-boost + hx-target to update a #main div, for instance.

If UI elements hook into htmx:configRequest, then a preload request may trigger some client-side action before the user actually commits to executing the request. A check for an hx-preload header can be used to avoid this.

Also, if an implementation uses the pattern of hx-boosted <a href=""> tags and server-side logic to return only partials when a request contains the hx-request header, then the preload would unnecessarily load an entire page when a snippet would suffice. So, I've added an hx-request and hx-preload header to the XMLHTTPRequest as well.

Please let me know what you think about this change.

also added hx-request header to href preload requests, in case implementations rely on hx-boost + hx-target to update a #main div, for instance
Copy link

netlify bot commented Jul 24, 2024

Deploy Preview for htmx-extensions canceled.

Name Link
🔨 Latest commit fb62007
🔍 Latest deploy log https://app.netlify.com/sites/htmx-extensions/deploys/66a121f96dc9740008c1553e

@bogdano bogdano changed the title added a "hx-preload" header to hx-get and href requests preload: added a "hx-preload" header to hx-get and href requests Jul 24, 2024
@bogdano
Copy link
Author

bogdano commented Jul 24, 2024

I apologize if I should have just opened an issue instead-- I didn't see any contribution guidelines until after I submitted the PR and checked the base htmx repo...

@Telroshan Telroshan added the enhancement New feature or request label Jul 25, 2024
@Telroshan
Copy link
Collaborator

Hey,

  • To remain consistent with the main lib's headers, I would use uppercase for HX prefix and the first letter of the header, as in
    https://github.com/bigskysoftware/htmx/blob/45566e126edd51bd24ff67871d662d6fc5b5934d/src/htmx.js#L3131
  • Adding a test case would be nice, just to ensure the headers are properly set in all situations, and prevent future potential regressions
  • No worries! There are no contribution guidelines for this repo atm indeed (at some point we'll add some), and as it's still relatively small, we can manage unsollicited PRs for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants