If my web app consists of more than one subdomain, does that mean I have to have multiple service workers, one for each subdomain? Or can I have one service worker that works across subdomains?
相关问题
- PWAs on iOS 12 no longer shares Service Worker cac
- Are promises lazily evaluated?
- start_url does not respond with a 200 when offline
- Adding a new header to a Request, while preserving
- unable to post message to service worker because c
相关文章
- Checking for service worker updates in a single pa
- Progressive web app(PWA) vs Electron vs Browser ex
- Is there a way to add badge notifications using pr
- Uncaught (in promise) DOMException: Quota exceeded
- Manifest start_url is not cached by a Service Work
- Why does fetch request have to be cloned in servic
- Media Notifications using the Media Session Web AP
- Get page URL parameters from a service worker
Each subdomain is considered a different origin and you must register a service worker for each origin but you can reuse the same source for the service worker by setting the
Service-Worker-Allowed
response header to the list of scopes the same source can control.If you mean by multiple domains is that the user can access your site directly on multiple domains like
www.example.com
andhello.example.com
then I believe the answer is yes, you need multiple service workers to handle each.However, if your main app is served on one domain
www.example.com
but might call other domains likeapi.example.com
orimages.examples.com
or evenfonts.gstatic.com
to load Google Fonts orexample.s3.amazonaws.com
to load static assets then a single service worker is enough. This is how you can catch and cache (or do whatever you'd like to the requests):In the example I am using sw-toolbox library from Chrome team to help you cache different assets.
Each subdomain is considered a different origin, so yes, you will need to register a service worker for each one. Each of these workers will have its own cache and scope.