Blazor Wasm PWA not updating

Faheem Husain Rizvi 6 Reputation points
2023-01-23T17:19:09.8266667+00:00

After publishing blazor wasm app it will not updating it shows old version every time we performed hard reload and clearing cache and cookies then it will update. Please provide me solution to fix this issue

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,615 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Tasadduq Burney 8,431 Reputation points MVP
    2023-01-23T17:37:09.8033333+00:00

    This issue is likely caused by the browser caching the old version of your Blazor WASM app. To fix this issue, you can try the following solutions:

    1. Add a cache busting mechanism to your app: This involves appending a unique query string parameter to the URLs of your app's assets (e.g. JavaScript and CSS files) every time you update and deploy your app. This will force the browser to download the new version of the assets.
    2. Set the appropriate cache control headers on your app's assets: By setting the "Cache-Control" header to "no-cache" or "no-store", you can ensure that the browser will always check for a new version of the assets before loading them.
    3. Use a service worker to handle caching: A service worker is a script that runs in the background of the browser and can control how assets are cached. By using a service worker, you can ensure that the browser always loads the latest version of your app.
    1 person found this answer helpful.

  2. ULRICH SCHUMACHER 5 Reputation points
    2024-09-03T17:01:20.22+00:00

    With each publish, VS creates a service-worker-assets.js file. The service worker checks this file and compares the hash codes to decide if the cached files are up-to-date.

    The problem is, that the service-worker-assets.js file itself is cached by default (not in the HTML cache, but in the service worker cache). So if you upload a new version to your server (with a new service-worker-assets.js), the service worker uses the cached service-worker-assets.js to decide if a new version is available. This is nonsense.

    To stop that, register the service worker in index.html like this:

    <script>navigator.serviceWorker.register('service-worker.js', { updateViaCache: 'none' });</script>

    https://learn.microsoft.com/en-us/aspnet/core/blazor/progressive-web-app?view=aspnetcore-8.0&tabs=visual-studio

    This one took me days to solve, hope it helps.

    PS The app must be started two times, to make the update work. The first time, only the cache is refreshed. To avoid this skipWaiting can be used.

    1 person found this answer helpful.
    0 comments No comments

  3. Bruce (SqlWork.com) 66,706 Reputation points
    2023-01-23T18:20:13.3833333+00:00

    most browsers you can configure to not cache when the dev tools are open.

    0 comments No comments

  4. Marek Ištvánek 0 Reputation points
    2023-05-09T13:31:12.87+00:00

    I have the same problem.
    My Blazor Wasm PWA application for .NET 7 created in VS 2022 17.5 is not updated in a browser after it is uploaded to hosting.
    So basically the update process described at
    https://learn.microsoft.com/en-us/aspnet/core/blazor/progressive-web-app?view=aspnetcore-7.0&tabs=visual-studio#background-updates
    does not happen.
    I use Edge 113.0.1774.35 and close all browser tabs with my application.

    When I start the application again, it is never updated.

    When I open developer tools and click Update in Application part, the application is updated.

    0 comments No comments

  5. Bruce (SqlWork.com) 66,706 Reputation points
    2023-05-09T16:11:34.82+00:00

    the browsers trigger to update a PWA is a change to the manifest, or the service worker js file.

    the safest way to for users to get updates, is to change the urls in the service worker manifest file, by adding a version. you probably just need to make the WASM have a unique url.

    note: for development, just keep the dev tools open.

    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.