NetTalk Central

Author Topic: serviceworker.js in a web app?  (Read 3928 times)

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
serviceworker.js in a web app?
« on: July 21, 2019, 01:34:51 PM »
In the log for a NT10.35 server app I'm seeing lots of "GET /serviceworker.js" - is that to be expected? I can't even find that script anywhere. And what is it supposed to do for a server app?

Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: serviceworker.js in a web app?
« Reply #1 on: July 21, 2019, 11:56:19 PM »
>> In the log for a NT10.35 server app I'm seeing lots of "GET /serviceworker.js" - is that to be expected?

yes. The browser is asking for serviceworker.js. It doesn't exist in your case (which is fine) - but the browser keeps asking to be sure.

>> I can't even find that script anywhere.

You won't because it's not being generated for you. And indeed, it's not your _web app_ that's asking for it. It's a _browser_ thing - just like favicon.ico  -the browser asks for that as well.

>> And what is it supposed to do for a server app?

The short answer is that it allows your web app to use various APIs in the browser which require service workers. NetTalk 11 generates it for you in some cases (it's optional) but I think it might come more and more into play. It's mostly used by "apps" level at the moment but I _may_ (or may not) move it down to server level, depending on what I need to use it for.

Cheers
Bruce


peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: serviceworker.js in a web app?
« Reply #2 on: July 22, 2019, 12:49:24 AM »
Hi Bruce,

Thanks for the clarification/explanation. I do have NT11 Apps as well but just haven’t noticed it in NT10 before.

Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: serviceworker.js in a web app?
« Reply #3 on: July 22, 2019, 02:17:43 AM »
Hi Peter,

If you are testing on "the same address" - like say 127.0.0.1 - and you test with "apps" (some app that has a serviceworker) then that's "registered" in the browser, even when you go back to say an NT10 app.

You can unregister the service worker in Developer Tools, Application tab, Service-Workers section.

>> You won't because it's not being generated for you. And indeed, it's not your _web app_ that's asking for it. It's a _browser_ thing - just like favicon.ico  -the browser asks for that as well.

This is "sort of" wrong. (apologies). The request is coming from the browser, not the app, but it's because you _already_ have a service worker on that URL which is looking for an update. So yes, it's coming from the browser, but only because you put it there.

cheers
Bruce

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: serviceworker.js in a web app?
« Reply #4 on: July 22, 2019, 07:09:52 AM »
Hi Bruce,

Now, that really makes sense. I Think I started seeing it after I upgraded my NT11 from Server to Apps (on the same machine) so there you go.

Thanks
Peter