This commit is contained in:
2026-04-20 17:51:22 +03:30
commit c7aa105709
9 changed files with 719 additions and 0 deletions

BIN
public/images/ball.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
public/images/bird.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

30
public/index.html Normal file

File diff suppressed because one or more lines are too long

6
public/js/app.js Normal file
View File

@@ -0,0 +1,6 @@
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/sw.js")
.then(() => console.log("service worker is registed"))
.catch((e) => console.log(e));
} else console.log("there is no")

44
public/sw.js Normal file
View File

@@ -0,0 +1,44 @@
let CACHE_STATIC_NAME = "static-v1";
let CACHE_DYNAMIC_NAME = "dynamic-v2";
self.addEventListener("install", function (event) {
console.log("[SW install]", event);
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_STATIC_NAME).then((cache) => {
console.log("[SW precache]");
return cache.addAll(["/", "/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)
}
}))
}))
return self.clients.claim();
});
self.addEventListener("fetch", function (event) {
event.respondWith(
caches.match(event.request).then((res) => {
console.log("res", res);
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;
});
}
}),
);
});