1 parent 418f1f7 commit 0053bddCopy full SHA for 0053bdd
1 file changed
public/sw.js
@@ -0,0 +1,19 @@
1
+const CACHE_NAME = "todo-app-v2";
2
+const ASSETS = ["/", "/index.html"];
3
+
4
+self.addEventListener("install", (e) => {
5
+ e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS)));
6
+ self.skipWaiting();
7
+});
8
9
+self.addEventListener("activate", (e) => {
10
+ e.waitUntil(caches.keys().then(keys =>
11
+ Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
12
+ ));
13
14
15
+self.addEventListener("fetch", (e) => {
16
+ e.respondWith(
17
+ caches.match(e.request).then(cached => cached || fetch(e.request))
18
+ );
19
0 commit comments