I can’t find where I went wrong in my PWA

Asked

Viewed 26 times

0

Hi. I’m with a problem, I’m not understand why my service worker is not registering, I’ll send some prints and my code, I thank from now to all help

Imagens 1 Imagen 2

my sw.js code:

var CACHE_NAME = 'static-v10';
var DYNAMIC_NAME = 'dynamic-v10';

const resourcesToPrecache = [
    './index.html',
    './scss/style.scss',
    './js/main.js'
    ];


self.addEventListener('install', function(event) {
  // Perform install steps
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(resourcesToPrecache);
      }).catch(function(){
        console.log('failed to cache', error);
      })
    );
});


self.addEventListener('activate', function(event) {

  event.waitUntil(
    caches.keys().then(function(keyList) {
      return Promise.all(
        keyList.map(function(key) {
          if (key !== CACHE_NAME && key !== DYNAMIC_NAME) {
            return caches.delete(key);
          }
        })
      );
    })
  );
});

self.addEventListener('fetch', function(event) {
    e.respondWith(
        caches.match(e.request).then(function(r) {
            console.log('[Service Worker] Fetching resources:'+e.request.url);
        return  r || fetch( e.request).then(function(response){
            return caches.open(CACHE_NAME).then(function(cache){
        console.log('[Service Worker] Catching new resources'+e.request.url);
        cache.put(e.request, response.clone());
        return response;
                });
            });
        })
    );
});
  • According to Google documentation, your file manifest.json has to contain this key start_url.

  • it contains, I poked around and I managed to register the sw, but now is giving another error

1 answer

0

follows here the point that I arrived

imagem do console

url do manifest

fuction sw install

Browser other questions tagged

You are not signed in. Login or sign up in order to post.