diff options
Diffstat (limited to 'worker.js')
-rw-r--r-- | worker.js | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -33,10 +33,12 @@ self.addEventListener('install', function(event) { this.addEventListener('fetch', function(event) { var req = event.request.clone(); - if (!navigator.onLine) { - event.respondWith( - caches.match(req).then(function(resp) { + if (req.method != "GET") return; + event.respondWith( + caches.match(req).then(function(resp) { + + if (!navigator.onLine) { if (resp) return resp; if (req.url.match("read.html")) { @@ -46,7 +48,22 @@ this.addEventListener('fetch', function(event) { if (req.url.match("index.php")) { return caches.match("offline.html"); } - }) - ); - } + + return; + } + + //console.log("<<<", req.url); + + // refresh cached files + return caches.open(CACHE_NAME).then(function(cache) { + return fetch(req.url,{credentials: 'include'}).then(function(resp) { + return caches.match(req).then(function(match) { + if (match) cache.put(req.url, resp.clone()); + return resp; + }); + }); + }); + }) + ); + }); |