tjfdownsouth
tjfdownsouth

Reputation: 53

Blazor server force a cache reload

I have a webpage that I initially started as a Blazor WASM project with PWA checked, because of the initial load time I decided to change it to a Blazor server project. Everything is working fine now except for desktops that had opened the page while it was a WASM project. They completely ignore the server and just run the original web page, if I do a shift-control-r the new web page with show up but anytime I go back it shows the original WASM page.

Does anyone know of a way to get the original wasm to update to the new version client side. I even shut the web server off and the webpage still works locally it is like it never even checks back with the server.

Thanks, Tim

Upvotes: 1

Views: 2605

Answers (2)

Kasper Olesen
Kasper Olesen

Reputation: 136

I finally found an answer for this that helped me. If you do not need PWA, you can remove it and Chrome (and probably other browsers) should stop clinging on to an old client even after deleting cache and fully reloading. Because after having done this my Chrome still reloaded it. For my app I do not need to use this caching feature or to be able to install it as an app.

I found the answer here: Blazor Chrome caching issues

How 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" />

Also... to actually get rid of the app in Chrome, because I had already loaded it this way, I installed it as an app and then uninstalled the app and removed it from Chrome. That finally got me out of this whole loop with Chrome keeping the app.

Upvotes: 1

rdmptn
rdmptn

Reputation: 5603

You can try using server pre-rendering for the PWA, that might help with the original speed issue, while letting the users who already have the PWA keep using it as one.

Updating the PWA version in the service worker and handling a few events can let you prompt your users to update. Frankly, if they have the old version - I am not sure there's much you can do in case they don't download the new service worker. I can suggest you take a peek at this sample app to see one way of doing such a custom prompt. I had a pal who had to drop an entire app and start using a different home page precisely because they couldn't get old service workers to drop the cache on client devices.

Upvotes: 0

Related Questions