-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
AJAX calls should use text/html, */*
as value for Accept
header
#1229
Comments
I also support this, but consequently it should be possible to overwrite the accept header if other types are needed. |
AFAIK, this would be the vector to use today: https://htmx.org/events/#htmx:configRequest. but I tend to agree with @odrotbohm |
@netaisllc didn't know that such a configuration is already there (nice), nevertheless if you have to support multiple different header it would be nice to have a short way within the html tag to be able to configure it direct by the request. Like |
This would also help with HTTP caching of partials. If htmx would set the request header e.g.
And backends could also set the HTTP content negotiation FTW! |
htmx already passes the |
@jollytoad that doesn't work when you want to cache the response from an endpoint that could return full or partial response depending on the value of the header. Because you would need to set the I have already implemented this manually and it works perfectly. |
Relevant resources for anyone reading up on this for the first time (like me)
This seems important to me. Why not something like:
or even
if you wanted to try and come up with a generic name for elements that come from AJAX swapping, which I think could be a really good idea. |
I am good with any distinct content type, but if we want it to be RFC-compliant, maybe we can stick to |
If I'm reading the RFC right, I think different formats are separated by commas, with the semicolon for option modifiers. |
Actually, the more I think about this, the more I like the option modifiers, but I think it should be generic, not |
Maybe |
Should it also include the target if available too, as this may well affect the response considerably? (ie. currently passed in the HX-Target header value), eg: |
You can customize the header to return anything (even now). We are just discussing what the default should be, I don't see any good reason to include that level of granularity by default. The detail of whether it's a full page or a partial is an obvious one because of caching. |
Why would the same url return a different response when requested by HTMX vs not-htmx? And if it did (which it shouldn't?), why would it only have 1 possible response for the htmx response. If someone wants HTMX to get a partial view of a page, shouldn't they be requesting a different url? The url would include some indication to the server of what part of the resource it's requesting. For example:
|
The two reasons I've seen are progressive enhancement and composability. I don't think progressive enhancement is a reasonable goal for a modern website (yet, I think htmx could promote some browser standards that would change that) but in theory if JS is off, you get the whole page, if it's on you get a partial refresh. As for composability, a lot of htmx frameworks support a pattern where you get the full page on first load, and then get a fragment of that page if the |
Interesting.. that's surprising to me, and almost feels like something that should be discouraged by this library? Maybe I'm over thinking this though. That would require specific caching rules, or at least 🤔 what am I missing? |
@yawaramin the Vary header would still work appropriately here. Every response to the resource should contain The absence of the header in the request indicates one variation of the response, and then any actual value of |
Hi guys, would it be possible something like? text/html; partial=1; targets=[id1,idk] |
The use-case I have is where you have a GET endpoint such as Because HTMX is passing So in my case it is not about returning a partial vs full HTML page, but returning HTML vs an error. |
By default, HTMX doesn't seem to add any
Accept
header to the calls it issues to the server. This causes the servers to receive anAccept: */*
and doesn't give them a hint in case which media type to produce in case they can serve multiple ones for the same resource.As HTMX is so focussed on HTML as response media type, it would be nice if it expressed that in the HTTP headers it sends, advertising, that it is primarily interested in HTML.
The text was updated successfully, but these errors were encountered: