简体   繁体   中英

Angular PWA ngsw-config updateMode -- when will it update on user's PWA?

We recently deployed a production app using Ionic + Angular PWA. Unfortunately we didn't set updatemode for assets *.js & *.html. We have deployed a new version of ngsw-config and ngsw.json which includes a method for updating assets.

If a user has already installed our app on their phone (ie shortcut on home screen) -> how long will it take for their ngsw-config or ngsw.json to update?

Will it update automatically?

As per https://angular.io/guide/service-worker-devops#update-checks :

Every time the user opens or refreshes the application, the Angular service worker checks for updates to the app by looking for updates to the ngsw.json manifest. If an update is found, it is downloaded and cached automatically, and will be served the next time the application is loaded.

This means that the next time* your user opens the app, he should get the updated content/app because a new version of ngsw.json is available in the server.

Side note: I have not tried it myself. The only thing I am unsure of is whether the service worker always fetches the new ngsw.json file even if you explicitly set a Cache-Control: max-age... header on ngsw.json file. I think it will as Angular boasts a strong guarantee of app integrity. But, I would recommend you to experiment with it beforehand.

* (Note on "next time") If a user already "added to home screen" the previous version, when he opens the app again, the browser still renders the old app even if the new version is now available. This is because the service worker checks for updates to ngsw.json during this time and downloading the updated versions in the background. If the user closes and opens the app the second time, that is when the new version will be actually rendered. I have read somewhere (but I forget where) that a "new version is available, would you like to refresh" message can be shown during the first time a user opens the app after a new version is available, but that is out of scope of this question, so I won't dig into that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM