10000 Consider adding an HTTP header that indicates whether the response should be a fragment · Issue #4 · alexpetros/triptych · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Consider adding an HTTP header that indicates whether the response should be a fragment #4

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

Open
bparks opened this issue Nov 13, 2024 · 1 comment
A80F

Comments

@bparks
Copy link
bparks commented Nov 13, 2024

In the first example, clicking the "Home" link updates the items visible in the browser

<a href="/home" target="main">Home</a>
<main> <!-- Existing page content --> </main>

But presumably in keeping with HTTP/HTML/REST/Hypertext, the URL should change?

If I then go to http://MY_DOMAIN/home, the server should probably default to responding with the whole HTML page.

But then how do I indicate that I should only receive a fragment in response?

Options include:

  • Adding an HTTP header when the request is initiated from the link (e.g. X-Response-Type: fragment)
  • (Client-side) extracting the contents of main from the response before injecting into the current page
  • Some sort of other hackery (like sending a POST instead of a GET), but these start to feel extremely rough and clunky quickly.

My preference would be for adding an HTTP header, but maybe in a pinch (if some response header isn't present maybe) falling back to the client-side option.

@alexpetros
Copy link
Owner
alexpetros commented Nov 14, 2024

Hey thanks for the feedback! I agree with you that there should probably be a header, but I also think it's non-critical.

In a hypermedia system, you, author of the webpage and owner of the server, control what the URLs return. I don't see much justification for re-using the same URL to provide both partial-page updates and full-page navigations. If /home is meant for full-page navigations, it should always be used that way. I should update the example on the README, actually, to a route that more clearly communicates a partial change.

(htmx, for example, has an hx-request header that people use for progressive enhancement: if it's present they'll send the partial page update, if it's not they'll send the full page. It's a fine way to do progressive enhancement, but I also think it's overkill. You usually should just send the full page.)

Triptych also doesn't (currently) have a way for targeted links to update the URL because I believe that if the link needs to update the URL, it should just be a (full-page) navigation. I can do deeper into it, but the gist is that, in my opinion, navigations and partial page updates serve different semantic purposes, and I don't think that HTML semantics should (or need to) blur them.

Relatedly, one of the reasons that I feel so strongly that forms need to natively support methods like PUT and DELETE is because I want to use them in navigations, which JavaScript cannot properly simulate.

All that having been said—partial page replacements should definitely send some new request and response headers (I think retargeting from the server is especially crucial). I'm more than open to suggestions about what those should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0