So people have asked me to share how to make sure your PWA automatically updates itself, even on #iOS 12 (which preserves the state of your app even when quitting it). Thread follows.
In my case the app is stateless so I can allow myself to just reload the app without showing any prompts for update to the user. If your app is more complex you can show a prompt in every place I do `location.reload`, all other things should be relevant
Here& #39;s the point to listen if the new ServiceWorker is available: #L26">https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/serviceWorker.js #L26">https://github.com/psmb/cale...
When installing SW I do skipWaiting to make it take control immediately, without waiting for all tabs to be closed. Also I do `clients.claim` in order to take control of all the tabs that have no SW installed yet for some reason #L6-L11">https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/service-worker.js #L6-L11">https://github.com/psmb/cale...
On every route transition I compare the current app& #39;s version with the version returned by app& #39;s version endpoint: #L24">https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/Routes.js #L24
If">https://github.com/psmb/cale... the versions differ I reload. This is especially important on iOS 12 where there& #39;s no way to make the app to reload from user actions
On every deploy I tag a new version with `yarn version --patch`. Here& #39;s how I expose it server-side: #L73">https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/server.js #L73">https://github.com/psmb/cale...
I also display the version in the app, quite helpful when debugging: #L87">https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/containers/Main/BurgerMenu.js #L87
That& #39;s">https://github.com/psmb/cale... it! On every route transition I can be sure that the users have the latest version of the app.
This is my first experience with PWAs so I might have got things wrong. Please correct me. I might later expand this thread into a blog post.
You can follow @dimaip.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: