1

How can I make sure that the users of a Blazor client app always load the latest version of the code? I now have to instruct them to clear their browser caches every time a new version is published. This hampers the "release early and often" approach and I simply cannot believe that any serious blazor development is at all possible without checking for new versions at start up (what click once applications do).

I found this solution on https://learn.microsoft.com/en-us/answers/questions/214424/blazor-wpa-not-updating.html

/**
      * Register Service Worker
      */
     navigator.serviceWorker
         .register('/***.js', { scope: '/' })
         .then(() => {
             console.log('Service Worker Registered');
         });

This js file can contain a cache version like below.

 const CACHE_VERSION = 1.0

But that is too cryptic for me? How can I implement the solution stated above as in "for dummies"?

Dabblernl
  • 15,831
  • 18
  • 96
  • 148
  • [does this answer your question?](https://stackoverflow.com/questions/61169801/forcing-reload-of-blazor-client-after-publishing-changes) – klekmek Jan 09 '22 at 20:33
  • @klekmek: sorry it is too cryptic. I think I found how to do it, but still it does not work. The service-worker-published.js file is full of references to cached data. Perhaps the solution lies somewhere there – Dabblernl Jan 09 '22 at 21:06

1 Answers1

3

The answer is (once you know it) quite simple: In the index.html under the wwwrootfolder you will find:

  <script>navigator.serviceWorker.register('service-worker.js');</script>

Below this write:

 <script>navigator.serviceWorker.register('version.js');</script>

And create a "version.js" file in this folder with as single content:

const CACHE_VERSION = 1.0

Increment the 1.0 value each time you want your clients to load the new version.

It looks like this:

Once your clients have managed to clear their cache and load the version that contains this code, a simple reload or shut down and restart of the browser will make the new version active.

Dabblernl
  • 15,831
  • 18
  • 96
  • 148