7

I've been testing out Blazor, and I can't find any documentation on how to implement browser caching (either with static files like images, css, js etc, but also the dll files that are downloaded).

Is it possible to cache static and dll files in Blazor at all?

Paul
  • 9,409
  • 13
  • 64
  • 113
  • IIRC at least the `.dll` files are getting cached by default. – Twenty Jan 22 '20 at 10:21
  • 2
    I would think standard browser cache-control headers. You can inspect example headers here: https://blazor-demo.github.io/ – Matt Evans Jan 22 '20 at 10:28
  • @MattEvans Yep, that's the one, that works perfectly - I can't find the repo for it though to work out what's been applied in order to enable that cache – Paul Jan 22 '20 at 20:21
  • Does this help? https://learn.microsoft.com/en-us/aspnet/core/performance/caching/middleware?view=aspnetcore-3.1 – Matt Evans Jan 23 '20 at 06:49
  • UseStaticFiles configures caching. Check this https://stackoverflow.com/a/57254309/2224701 – Vojtěch Dohnal Jan 23 '20 at 06:52
  • @MattEvans That's what I'd normally do, but for the blazor app it's not working - the dll's are still downloading every time – Paul Jan 23 '20 at 13:20

1 Answers1

7

As of Blazor WASM 3.2-preview2 release, when an app is initially loaded, the runtime and framework files are now stored in the browser cache storage. When the app loads, it first uses the contents of the blazor.boot.json to check if it already has all of the runtime and framework files it needs in the cache. If it does, then no additional network requests are necessary.

You can read more about this in Improved framework caching section of the Blazor WASM release blog post.

Artak
  • 2,819
  • 20
  • 31
  • 1
    what about non-dll files like json files using for translating data or some other useful uses for example ? – Al-Hanash Moataz Apr 18 '20 at 21:02
  • 1
    Non-dll files (JSON, Images and other static assets) are just usual static assets, for which the standard caching strategies apply. If you have a hosted project, use the ASP.NET Core caching mechanism for that. This should help: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/response?view=aspnetcore-3.1 – Artak Apr 19 '20 at 03:40