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

Cache handling #50

Open
tanczosm opened this issue May 14, 2024 · 6 comments
Open

Cache handling #50

tanczosm opened this issue May 14, 2024 · 6 comments

Comments

@tanczosm
Copy link
Collaborator

Is there any attention to how browser caching is handled with requests that return full or partial results on the same url?

See https://htmx.org/docs/#caching

@egil
Copy link
Owner

egil commented May 14, 2024

I want to support this through the standard aspnet core Output caching functionality, and as far as I can tell, it should just work (at least it does in regular Blazor SSR).

Will need to experiment and make sure htmxor has not broken anything related to it though. Another source of inspiration may be: dotnet/aspnetcore#49130

This is related to #18.

@egil
Copy link
Owner

egil commented May 14, 2024

I confirmed that it "just works" with [OutputCache] and friends and Htmxor. However, current Htmxor is setting a xsrf cookie token on each request, which prevents caching from working, as caching disables itself when a cookie is set. So I will revisit the antiforgery token stuff.

@khalidabuhakmeh
Copy link

I would recommend OutputCache only be applied on non-mutating HTTP methods like GET which also don't require anti-forgery tokens. For mutating endpoints/functions (POST, PUT, and DELETE), folks should rely on server-side caching.

@egil
Copy link
Owner

egil commented May 29, 2024

Good point Khalid. Then it should just work now.

@tanczosm
Copy link
Collaborator Author

To be clear, if I know I'm going to be rendering potentially different content from the same endpoint url (full page vs partial page) depending on whether it's an htmx request or not I'm going to need to decorate each page with something like:

@attribute [OutputCache(VaryByHeaderNames = ["HX-Request"])]

@egil
Copy link
Owner

egil commented May 30, 2024

I think so @tanczos.

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

3 participants