egil / Htmxor

Supercharges Blazor static server side rendering (SSR) by seamlessly integrating the Htmx.org frontend library.
MIT License
109 stars 12 forks source link

Cache handling #50

Open tanczosm opened 2 months ago

tanczosm commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Good point Khalid. Then it should just work now.

tanczosm commented 1 month ago

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 commented 1 month ago

I think so @tanczos.