Skip to content

Blazor PWA on iOS: Service worker doesn't trigger updates on app deployment #19882

@SteveSandersonMS

Description

@SteveSandersonMS

Repro:

  • Deploy the published app; load it on an iOS device so it starts working offline
  • Make a change to Index.razor and republish and redeploy
  • Visit on the same iOS device
  • After giving it enough time to fetch the update in the background, navigate away to another page then navigate back

Expected: Should receive the update
Actual: Doesn't

This is because the update is meant to be triggered by the change to service-worker-assets.js (in that the content hash will have changed). However, at least as of Safari on iOS 13.3.1, the browser only checks for changes to service-worker.js and not to service-worker-assets.js. This is inconsistent with Chromium browsers which also check for changes to imported scripts. It's possible that iOS 13.4 might fix this, but it also might not.

In order to fix this, we need to change something in the publish flow so that we always make a modification to service-worker.js. For example, go back to the logic we had at an earlier stage whereby during publishing we always append // {GUID} to the file (using a random GUID).

Other issue

We should also change the service worker registration logic to look like this:

navigator.serviceWorker.register('service-worker.js', { updateViaCache: 'none' })

This updateViaCache setting tells the browser to bypass its HTTP cache when fetching service-worker-assets.js, which is exactly what we want it to do.

Metadata

Metadata

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions