How to register a service worker's scope one directory above where the service_worker.js is located

前端 未结 2 1797
别跟我提以往
别跟我提以往 2020-12-20 12:10

MY directories are as follows.

public_html/
sw/

The \"sw/\" is where I want to put all service workers, but then have those service workers

2条回答
  •  没有蜡笔的小新
    2020-12-20 13:13

    The max scope for a service worker is where it is located. This means you can not register one service worker located at /sw/ in scope: '/public_html/' unless you include a special header Service-Worker-Allowed set to the new max scope for your service worker.

    Summarizing, if you can add this header when serving the service worker, set it as follows:

    Service-Worker-Allowed: /public_html/
    

    If not, you must place the sw at some location above the scope.

提交回复
热议问题