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
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 keystart_url
.– TiagoA
it contains, I poked around and I managed to register the sw, but now is giving another error
– str4ct0r