Search code examples
reactjscreate-react-appservice-worker

Can create-react-app service worker help tell the user that the application has been updated before the page reloaded?


I have an application created with CRA and I have configured service worker so that when the page is refreshed it reloads static content, there is no problem.

But, the user may not reload pages for a long time (because the SPA application) and I want to somehow tell him that the application has been updated and he needs to finish the current work and refresh the page, can the service worker help in this? Or is it not its area of responsibility and I need another solution?


Solution

  • You can use push notifications using service worker to notify user about refreshing page in that case. Besides, you can also implement web socket for sending such kind of notifications to the user.

    You can go through following link to get idea how to implement push notifications with service worker.

    How to implement Web Push Notifications in your Node / React app

    https://medium.com/@seladir/how-to-implement-web-push-notifications-in-your-node-react-app-9bed79b53f34
    

    React Push notifications (with hooks)

    https://itnext.io/react-push-notifications-with-hooks-d293d36f4836
    

    Thanks