Error 404 when trying to register a Worker service

I get this error when trying to register a service worker:

Failed to register ServiceWorker: Bad HTTP response code (404) was received while fetching the script.

I work with ionic, and this is what I have in app.js:

   if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js').then(function(registration) {
      console.log('ServiceWorker registration successful with scope: ', registration.scope);
    }).catch(function(err) {
      //registration failed :(
      console.log('ServiceWorker registration failed: ', err);
    });
  }else {
    console.log('No service-worker on this browser');
  }

In the directory, I have a service-worker.js file next to app.js in the same folder.

Using the latest version of chrome on the ubuntu desktop.

+4
source share
2 answers

, service-worker.js , app.js, URL-, .register(), HTML. , service-worker.js , .html, .

+18

HTML, SW.js, .

enter image description here

+1

Source: https://habr.com/ru/post/1588887/


All Articles