summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--worker.js29
1 files changed, 23 insertions, 6 deletions
diff --git a/worker.js b/worker.js
index 219947f..88a97c4 100644
--- a/worker.js
+++ b/worker.js
@@ -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;
+ });
+ });
+ });
+ })
+ );
+
});