how to register a service worker from different sub domain

前端 未结 4 1166
别那么骄傲
别那么骄傲 2020-12-06 00:26

I have two subdomains: https://abc.xxxx.com and https://xyz.xxxx.com. So my questions:

1). is it possible to register a service worker for https://x

4条回答
  •  盖世英雄少女心
    2020-12-06 00:59

    Here are some general answers that I think should address the various points you raise in your question:

    • Each registered service worker has an associated scope, which dictates the set of web pages that the service worker can control. The scope of a service worker is a URL, and that URL must have the same origin as the page that registers the service worker, and must be either a URL that corresponds to the same path level as the page or a path that's one or more levels down. The default scope corresponds to the same path level as location of the service worker script. Because of this restriction, it's not possible to call navigator.serviceWorker.register(...) from a page on one (sub-)domain and end up with a service worker that controls pages on another (sub-)domain.

    • There are restrictions in place to prevent you from throwing an https: