Friday 23 October 2020

Angular Service Worker intermittently serving old version of application

I have an Angular application (version 7.2.2) using the Angular Service Worker (version 7.2.12).

The service worker intermittently serves an old version of the application. On refresh the new version is shown, but if the user closes and reopens the browser tab, it reverts back to the old version until the next page reload. The ‘/ngsw/state’ page also has no errors when the old version is displayed.

I have not been successful in consistently reproducing the issue. In part because I am unsure of the cause. I have often gone weeks without having the service worker serve an old version of the code.


Some of the potential solutions I tried which seemed promising include:

  • Updating angular and service worker to the latest versions (at the time).
  • Removing caching from ngsw-config.json to prevent hash mismatches.
  • Adding checks for updates in multiple code locations.
  • Checking for updates on an interval.
  • Forcing a reload when an update is available – this sometimes occurs, but sometimes a manual reload is required to get the new version.


from Angular Service Worker intermittently serving old version of application

No comments:

Post a Comment