You can not find ServiceWorker

1

I have a project with Laravel, Vuejs and I want it to be PWA, I already have the service-worker, the manifest.json and I made the change to package.json, But I have a doubt, for now this localhost: 8000 and tells me

ServiceWorker registration failed:  TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

Why is this happening? What do I need for the service-worker to recognize me and thus be a PWA.

    
asked by Bella 03.04.2018 в 09:02
source

1 answer

1

This is the code I use to register the service worker, I've used it with Laravel without problem:

if (navigator.serviceWorker.controller) {
  console.log('Service worker already registered.')
} else {
  navigator.serviceWorker.register('service-worker.js', {
    scope: './'
  }).then(function(reg) {
    console.log('Service worker has been registered for scope:'+ reg.scope);
  });
}

This code is in a partial view that is loaded on all pages, basically, and the service-worker.js file is in the public folder.

    
answered by 03.04.2018 / 17:16
source