Service-worker scope?

I am working on a PWA and would like to know if the scope or directory where the service-worker file is located can interfere, such as in push notifications.

Will a file that is inside /statics/sw.js work the same way as one that is at the root of the project??

Author: LeonardoEbert, 2018-04-17

1 answers

A file inside / statics / sw.will js work the same way as one that is at the root of the project??

It won't work , it will only have access to fetch events that start with /statics

Referencia:https://developers.google.com/web/fundamentals/primers/service-workers/?hl=pt-br

A subtle point of the register () method is the location of the service worker file. In this case, you will notice that the service worker is at the root of the domain. This means that the scope of the service worker will be the full source. In other words, this service worker will receive fetch events for everything in this domain. If we register the service worker file in /example / sw.js, it will see only fetch events from pages with URL starting with /example /(i.e./example/ page1/,/example/page2/).

 2
Author: David Schrammel, 2018-04-17 19:09:56