I'm new to PWA and i'm training on a simple project. After the first run on goole chrome, for which everything worked fine, I changed the cacheName const in the service worker and the title in the index.html to test the re-caching of all site assets. From here on the cache still creates but it is empty and i get the error "Uncaught (in promise) TypeError: Request failed" referred to the line of SW we const staticCacheName = 'site-static-v1' is declared.
Here the code of SW:
const staticCacheName = 'site-static-v2';
const assets = [
'./',
'./index.html',
'./index.js',
'./main.js',
'./style.css',
'https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css',
'https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js',
'https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.1/proj4.js',
'https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.1/proj4-src.js'
];
// install service worker
self.addEventListener('install', evt => {
console.log('service worker has been installed');
evt.waitUntil(
caches.open(staticCacheName).then(cache => {
console.log('caching shell assets');
cache.addAll(assets);
})
);
});
// activate event
self.addEventListener('activate', evt => {
console.log('service worker has been activated');
});
// fetch event
self.addEventListener('fetch', evt => {
evt.respondWith(
caches.match(evt.request).then(cacheRes => {
return cacheRes || fetch(evt.request);
})
);
});
Any help will be greatly appreciated.