Scope of service-worker?

0

I'm working on a PWA and would like to know if the scope or directory where the service-worker file is located might interfere with, for example, push notifications.

Does a file within /statics/sw.js work in the same way as one that is in the project root?

    
asked by anonymous 17.04.2018 / 15:50

1 answer

2
  

Is a file within /statics/sw.js working in the same way as one that is in the root of the project?

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

Reference: link

  

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 file is at the root of the domain. This means that the scope of the service worker will be the complete source. In other words, this service worker will receive fetch events for everything in that domain. If we register the service worker file in /example/sw.js, it will only see fetch events from URL pages starting with / example / (ie / example / page1 /, /example/page2/).

    
17.04.2018 / 21:09