diff --git a/public/help/index.html b/public/help/index.html new file mode 100644 index 0000000..86090bc --- /dev/null +++ b/public/help/index.html @@ -0,0 +1,11 @@ + + +
+ + +
+
+
+
+
+
diff --git a/public/sw.js b/public/sw.js
index 8e879a0..4975379 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -1,5 +1,5 @@
-let CACHE_STATIC_NAME = "static-v1";
-let CACHE_DYNAMIC_NAME = "dynamic-v2";
+let CACHE_STATIC_NAME = "static-v2";
+let CACHE_DYNAMIC_NAME = "dynamic-v3";
self.addEventListener("install", function (event) {
console.log("[SW install]", event);
@@ -7,21 +7,25 @@ self.addEventListener("install", function (event) {
event.waitUntil(
caches.open(CACHE_STATIC_NAME).then((cache) => {
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) {
console.log("[SW activate]", event);
- event.waitUntil(caches.keys().then((keys) => {
- console.log("removing the old cache")
- return Promise.all(keys.map(key => {
- if (key !== CACHE_STATIC_NAME) {
- return caches.delete(key)
- }
- }))
- }))
+ event.waitUntil(
+ caches.keys().then((keys) => {
+ console.log("removing the old cache");
+ return Promise.all(
+ keys.map((key) => {
+ if (key !== CACHE_STATIC_NAME) {
+ return caches.delete(key);
+ }
+ }),
+ );
+ }),
+ );
return self.clients.claim();
});
@@ -32,12 +36,18 @@ self.addEventListener("fetch", function (event) {
if (res) {
return res;
} else {
- return fetch(event.request).then((res) => {
- // caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
- // cache.put(event.request.url, res.clone());
- // });
- return res;
- });
+ return fetch(event.request.url)
+ .then((res) => {
+ return caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
+ cache.put(event.request.url, res.clone());
+ return res;
+ });
+ })
+ .catch(() => {
+ return caches.open(CACHE_STATIC_NAME).then((cache) => {
+ return cache.match("/offline.html");
+ });
+ });
}
}),
);