Htmxor icon indicating copy to clipboard operation
Htmxor copied to clipboard

Cache handling

Open tanczosm opened this issue 1 year ago • 6 comments

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

tanczosm avatar May 14 '24 13:05 tanczosm

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: https://github.com/dotnet/aspnetcore/issues/49130

This is related to #18.

egil avatar May 14 '24 17:05 egil

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.

egil avatar May 14 '24 22:05 egil

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.

khalidabuhakmeh avatar May 29 '24 17:05 khalidabuhakmeh

Good point Khalid. Then it should just work now.

egil avatar May 29 '24 18:05 egil

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"])]

tanczosm avatar May 30 '24 13:05 tanczosm

I think so @tanczos.

egil avatar May 30 '24 17:05 egil