Service workers solve the page loading part by letting you serve content from a cache. But what about when the page needs to send something to the server
Use it to schedule any data sending that you care about beyond the life of the page. Chat messages, emails, document updates, settings changes, photo uploads. Anything that you want to reach the server even if user navigates away or closes the tab.
The page could store these in an "outbox" store in indexedDB, and the service worker would retrieve them, and send them on connection to the internet. Although, you could also use it to fetch small bits of data as well
Remember to add it to your pages at the botton of your project's pages as hown below
<!-- Add background sync --> <script src="js/sync.js"></script>