offline.html
This commit is contained in:
11
public/help/index.html
Normal file
11
public/help/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>help page</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
19
public/offline.html
Normal file
19
public/offline.html
Normal file
File diff suppressed because one or more lines are too long
36
public/sw.js
36
public/sw.js
@@ -1,5 +1,5 @@
|
|||||||
let CACHE_STATIC_NAME = "static-v1";
|
let CACHE_STATIC_NAME = "static-v2";
|
||||||
let CACHE_DYNAMIC_NAME = "dynamic-v2";
|
let CACHE_DYNAMIC_NAME = "dynamic-v3";
|
||||||
|
|
||||||
self.addEventListener("install", function (event) {
|
self.addEventListener("install", function (event) {
|
||||||
console.log("[SW install]", event);
|
console.log("[SW install]", event);
|
||||||
@@ -7,21 +7,25 @@ self.addEventListener("install", function (event) {
|
|||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CACHE_STATIC_NAME).then((cache) => {
|
caches.open(CACHE_STATIC_NAME).then((cache) => {
|
||||||
console.log("[SW precache]");
|
console.log("[SW precache]");
|
||||||
return cache.addAll(["/", "/index.html", "/js/app.js"]);
|
return cache.addAll(["/", "/index.html", "/offline.html", "/help/index.html", "/js/app.js"]);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("activate", function (event) {
|
self.addEventListener("activate", function (event) {
|
||||||
console.log("[SW activate]", event);
|
console.log("[SW activate]", event);
|
||||||
event.waitUntil(caches.keys().then((keys) => {
|
event.waitUntil(
|
||||||
console.log("removing the old cache")
|
caches.keys().then((keys) => {
|
||||||
return Promise.all(keys.map(key => {
|
console.log("removing the old cache");
|
||||||
|
return Promise.all(
|
||||||
|
keys.map((key) => {
|
||||||
if (key !== CACHE_STATIC_NAME) {
|
if (key !== CACHE_STATIC_NAME) {
|
||||||
return caches.delete(key)
|
return caches.delete(key);
|
||||||
}
|
}
|
||||||
}))
|
}),
|
||||||
}))
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
return self.clients.claim();
|
return self.clients.claim();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,12 +36,18 @@ self.addEventListener("fetch", function (event) {
|
|||||||
if (res) {
|
if (res) {
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return fetch(event.request).then((res) => {
|
return fetch(event.request.url)
|
||||||
// caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
|
.then((res) => {
|
||||||
// cache.put(event.request.url, res.clone());
|
return caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
|
||||||
// });
|
cache.put(event.request.url, res.clone());
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
return caches.open(CACHE_STATIC_NAME).then((cache) => {
|
||||||
|
return cache.match("/offline.html");
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user