Question: Currently, a webapp made with create-react-app only checks for updates when it first loads using the registerServiceWorker function. If the app is added to a phone's homescreen, it may never close, and so it never checks for new versions. Is there a recommended way to get it to check more often? For example, setting an interval and calling register every day or so. The extreme solution would be to just call window.location.reload() periodically, but I am hoping for a less disruptive solution. What is the best approach?
cc @jeffposnick
The assumption that updates are only triggered when there's a call to registerServiceWorker() is incorrect.
A service worker will check for updates whenever there's a navigation request (and a few other scenarios).
In practice, apps that are added to the homescreen don't live forever. When an Android device determines that it can free up memory by cleaning up the activity/process/(whatever Android calls it) it will do so. When you revisit your web app after it's been cleaned up, a new navigation request for the start URL will be fired. At that point, there will be a check for an updated service worker.
That being said, if you continuously use a web app for an extended period of time without ever switching it into the background, and that web app is a single page app, like many create-react-app projects are, there won't be any navigation requests fired. I'm not sure that it makes sense to optimize around that scenario in a general framework like create-react-app.
Thanks for the super detailed response!
Most helpful comment
The assumption that updates are only triggered when there's a call to
registerServiceWorker()is incorrect.A service worker will check for updates whenever there's a navigation request (and a few other scenarios).
In practice, apps that are added to the homescreen don't live forever. When an Android device determines that it can free up memory by cleaning up the activity/process/(whatever Android calls it) it will do so. When you revisit your web app after it's been cleaned up, a new navigation request for the start URL will be fired. At that point, there will be a check for an updated service worker.
That being said, if you continuously use a web app for an extended period of time without ever switching it into the background, and that web app is a single page app, like many
create-react-appprojects are, there won't be any navigation requests fired. I'm not sure that it makes sense to optimize around that scenario in a general framework likecreate-react-app.