Blazor Chrome caching issues
Asked Answered
S

4

8

I have this Blazor SPA I have published to IIS on a webhotel. My problem is that Chrome is somehow caching my Blazor assembly so no matter how many times I redeploy I still get the old dll. I can start up a new clean Chrome with chrome --disable-application-cache --incognito and that does indeed get the fresh dll but how do I fix this properly? Kind regards

Scintillator answered 10/3, 2020 at 7:54 Comment(0)
V
12

The following helps IF you don't want PWA features.

I started my project with PWA (just in case I wanted it later) but it turned out to cause this problem even when simply browsing. Tried adding comments or versioning to service-worker.published.js but that didn't help. I'm using Blazor version 3.2.1.

With PWA. When checking the cache in the browser I do see the latest service-worker.published.js appearing, and a new offline cache does get downloaded. But the browser keeps using the older ones for a reason beyond my understanding.

enter image description here

To remove PWA:

  1. Delete the following files from wwwroot:
/wwwroot/manifest.json
/wwwroot/service-worker.js
/wwwroot/service-worker.published.js
  1. Delete this line from /wwwroot/index.html
<script>navigator.serviceWorker.register('service-worker.js');</script>
  1. Delete those lines from your csproj file
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
Vellicate answered 20/8, 2020 at 4:54 Comment(4)
Thanks Waleed. The funny thing is that I don't have the same problem anymore. And I am even on Blazor 3.2.1Scintillator
Maybe you didn't enable PWA in the first place in this project?Vellicate
Thanks for your steps for removing a PWA.Danseur
This removed PWA, but does not fix the cache issueDefrost
O
1

The cache issue is pretty strange. I had a lot of trouble solving it as well and what seemed to work was that I in Chrome installed it as an app when it had loaded the old cache. I could do the force full refresh, but as soon as I did a new regular refresh it would go back to the old DLL cache. But after installing it as an app in Chrome, inside that app which I could uninstall it, and it also had the option to remove it from Chrome as well. Then it finally began loading my new version of the app... where I had done as Waleed Al Harthi suggests, to remove PWA and avoid this issue in the future.

Oskar answered 16/11, 2021 at 11:11 Comment(0)
L
0

Exactly like you do it. But of cause there are also other ways.

  1. Press F12 in the Browser -> Select Network -> Check Disable cache
  2. Press F12 in the Browser -> In developer mode R Click on reload -> Select hard reload
  3. Press ctrl+shift+R to hard reload
  4. Your way but create a shortcut for it.
  5. Disable cache with code (not recommended and i would have to lookup how)
Legibility answered 10/3, 2020 at 8:45 Comment(1)
OP wants to show the new version to every visitor of his SPA. Every visitor should not have to hard reload just to see the new version.Beardless
A
0

Enable it as a PWA

Then you can control the cache with a property in your project. The client will cache your code until you tell it to update - the user will be told there is an update and should reload the page - at this point it will update.

Adroit answered 10/3, 2020 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.