Blazor WPA not updating

Lex K 31 Reputation points
2020-12-30T13:40:57.44+00:00

I published a Blazor WPA to a static website (using Azure storage account), however now every time I publish an update to the website, the users keep continue using the cached version of the site, rather than the new version of the site.

I've tried various things already, but none of them cause the website to update correctly without a hard refresh. including add/update a comment in the service-worker.published.js file, which seems to have done the trick on older versions of Blazer.

Developer technologies .NET Blazor
0 comments No comments
{count} vote

Accepted answer
  1. Michael Wang-MSFT 1,061 Reputation points
    2020-12-31T08:58:54.173+00:00

    Hi, @Lex K ,

    Here are some solutions for u to update.

    • Open New InPrivate Window

    52474-image.png

    and input your url to broswer your website.

    52448-image.png

    • Empty cache

    Open Settings.

    52511-image.png

    Click "Privacy search and services"

    52467-image.png

    Select "Cached images and files" cache and refresh again.

    52409-image.png

    • Change version code of your Blazor PWA

    Declare a js file for registration in the navigator.serviceWorker object.

        /**  
         * 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.  
    

    Update cache_version when the code changes to force the cache to refresh. Anytime the register *.js file changes, the browser updates the service worker to its new version.

    const CACHE_VERSION = 1.1;  
    

    If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Michael Wang

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Stef Heyenrath 1 Reputation point
    2021-06-28T17:52:47.563+00:00

    Hello Michael Wang,

    Should I use this code:

    navigator.serviceWorker
        .register('version.js')
        .then(() => {
            console.log('version.js registered');
        });
    
    navigator.serviceWorker
        .register('service-worker.js')
        .then(() => {
            console.log('service-worker.js registered');
        });
    

    Or this code:

    navigator.serviceWorker
        .register('version.js')
        .then(() => {
            console.log('version.js registered');
    
            navigator.serviceWorker
            .register('service-worker.js')
            .then(() => {
                console.log('service-worker.js registered');
            });
        });
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.