-
Notifications
You must be signed in to change notification settings - Fork 51
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 extension: hx-boost, no side effects, HX-Preloaded header, form support, tests and JSDocs #106
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for htmx-extensions canceled.
|
this patch is working great for me in combination with hx-boost. essentially it "just works" while the main branch version doesn't. however, the loading indicator is visible when pages are being preloaded. |
Looks greats so far but +1 on the indicators, I don't believe these should be visible for preloads. |
@untitaker and @ALameLlama, thank you for reviewing my pull request. I agree with you. I implemented a change which prevents loading indicators to be shown while preloading nodes. I have also added a |
EDIT: ALameLlama helped pointing out I was missing Cache-Control from my response headers. All is good 😌
GET /blog/inquit-incepta HTTP/1.1
Host: 127.0.0.1:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:132.0) Gecko/20100101 Firefox/132.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
HX-Request: true
HX-Current-URL: http://127.0.0.1:3000/blog
HX-Boosted: true
- HX-Preloaded: true
Sec-GPC: 1
Connection: keep-alive
Referer: http://127.0.0.1:3000/blog
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
DNT: 1
Priority: u=0
|
What do your response headers look like? I have a feeling you're missing the Cache-Control. https://htmx.org/extensions/preload/
The new request header HX-Preloaded shouldn't have any effect on it. just give the BE more information about what triggered the request. |
Oof I'm silly. I just added the Cache-Control header and it's all good now. (I blame axum and askama_axum for making adding that in so difficult :P ) Here was my old response headers. HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 5740
- date: Thu, 21 Nov 2024 04:22:51 GMT
+ date: Thu, 21 Nov 2024 04:22:52 GMT Also I tried the |
It would be great to get somebody review this pull request. Merging it would allow us to close 10 issues, which is a lot given there are only roughly 30 issues reported in this repository. @Telroshan seems that the most recent PRs in the repo have been reviewed by you. Have you had a chance or are you planning to look at this one? Do you have any worries about it? If helpful, we can connect. The author of the original preload extension is @benpate bigskysoftware/htmx#273, and it was approved by @1cg. Maybe we can get some inputs from the original authors if they are still active in this repo? |
Hey @marisst , first of all thanks for your work. Life's currently a bit hectic so I haven't had the chance yet to sit down and review this PR as it should be. Can't guarantee a date that I'll look into it, but I hope to do it in the upcoming weeks. |
Major update of the preload extension.
<a href="link" hx-boost="true" preload>Link</a>
will be preloaded using XML request withoutHX-Request
headers.HX-Request
andHX-Boosted
headers is sent, and the cached request may not be used by the browser resulting in double loading.<form method="get" target="/link" hx-boost="true" preload>
withHX-Request
.preload
extension asking the server for pages without the necessary headers? #89hx-get
attribute, the preload will cause loading indicators to show upHTMX.ajax()
is used only to generate thexhr
request (incl. headers), which is manipulated inhtmx:beforeRequest
and sent without executing HTMX callbacks.htmx-request
class onbody
#115HX-Preload
header is added to all preload requests<form hx-get="/link" preload>
will preload the form with as-is values whenever user clicks or hovers (ifpreload="mouseover"
) on any of the forms elements.<input type="radio">
,<input type="checkbox">
or<select>
elements, it is more likely that the value of those elements will be changed first and then the form submitted.<form method="get" target="/link" preload>
will also be preloaded. Elements other than radio buttons, checkboxes, select elements and submit buttons are not triggering form preloading.<button hx-get="/link" hx-ext="preload" preload>Button</button>
is not preloaded in current version, but it is preloaded with the change. The reason is that the extension currently does not consider the element in which the extension is registered among the pool of nodes it initializes.touchstart
event listener was added to node as an alternative tomousedown
andmouseover
events for touchscreens, but it was not working because the correctnode.preloadState
was not set when callingload(node)
const funct = function(){}
withfunction funct() {}
declarations, which allow to change the order.node.preloadState
values are currently confusing.PAUSE
is used for when node is initialized,READY
for when data is loading andDONE
for when loading is complete. I have renamedPAUSE
toREADY
,READY
toLOADING
and keptDONE
. I also added a new stateTIMEOUT
used to check that user hovers over an element for at least 100ms before it starts loading.preload="always"
documentation and config flexibilitypreload="always"
propertypreload="always"
, currently it can only be used together with preload mode e.g.preload="always mousedown"
Documentation is updated in a corresponding pull request in the main xtmx repository. bigskysoftware/htmx#3001