3

Now service worker is called with:

 navigator.serviceWorker.register('/js/sw.js')
        .then(function (swReg) {

Can I call it like that:

var sw = //paste here all sw.js file's code;
navigator.serviceWorker.register(//call sw variable)
            .then(function (swReg) {

I know that serviceWorker.register can contain only path to sw.js but can I embed sw.js in app.js in someway?

Stack1233
  • 85
  • 5
  • 2
    No. Because it runs on a scope different than the DOM. https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API explains it better. – IT goldman Jun 22 '22 at 19:33
  • @ITgoldman Thank you for reply. app.js will be used on different sites and it works only when domain has sw.js on its server. Can I include sw.js with url in app.js and then register service worker? – Stack1233 Jun 22 '22 at 19:54
  • Probably not. Needs to be on same domain https://stackoverflow.com/a/72382370/3807365 – IT goldman Jun 22 '22 at 20:01

0 Answers0