Problem with PWA (Does not load from Cache)

0

I have a problem, I made a system with PWA (Progressive Web App) that works perfectly does the cache in the browser, but when I put in Offline mode, instead of pulling from the cache, the site appears the game Dinosaur!

Where is the error in the code below? (Although not shown below I make the request to this file in index.html)

var cacheName = "beta-v1.0";
var filesToCache = [
'../index.html',
'../manifest.json',
'pwa.js',
'sw.js',
'../logo.png'
]
self.addEventListener('install', function(event) {
event.waitUntil(
    caches.open(cacheName).then(function (cache){
            return cache.addAll(filesToCache)
    })
    .then(function () {
        return self.skipWaiting()
    })
)
})
self.addEventListener('activate', function(event){
event.waitUntil(
    caches.keys().then(function (keyList){
        return Promise.all(keyList.map(function (key){
            if(key !== cacheName) return caches.delete(key)
        }))
    })
)
return self.clients.claim()
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
  return response || fetch(event.request);
})
);
});
    
asked by anonymous 12.04.2018 / 23:29

0 answers