Given a website that is partly public and partly an internal web application, the goal is to enable a service worker (and PWA) only for the internal routes, but not register it for the public ones.
We have:
https://example.com
- Public Websitehttps://example.com/internal
- Internal website, would like to offer as a PWA
When a user visits the public website, I do not want to register a service worker. He can then choose to log in and is then redirected to the internal web-application, which we would like to offer with PWA capabilities.
Reading the documentation (https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#parameters), there should be a possibility to scope the ServiceWorker to the route /internal
:
navigator.serviceWorker.register('/sw.js', {scope: './internal'})
Why do I want this behavior? Because of the caching mechanisms: users visiting the public page are not coming back for a long time. If they come back after one year, they will see the old website while the Service Worker updates. On the other hand, users visiting the internal website will visit a lot more often. If they see a stale version, it will not be stale for long.
Is scoping the internal pages going to work and what are the implications?
For example, someone could choose to install a PWA, but in that case,he would be installing the internal webpage only? And what about the manifest? Should there be two manifests (public / internal) or only one for the internal page?