summaryrefslogtreecommitdiffhomepage
path: root/public/sw.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/sw.js')
-rw-r--r--public/sw.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/public/sw.js b/public/sw.js
index 571f752..64e8255 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -1,10 +1,14 @@
// 公園ページはドラフト公開停止中のため、公園ページをAPP_SHELLから外し、
// キャッシュを v2 に更新して旧キャッシュを削除する。公開時に元に戻す。
-const CACHE = "kodaira-parks-v2";
+const CACHE = "kodaira-events-v3";
const APP_SHELL = [
"/manifest.webmanifest",
+ "/manifest-events.webmanifest",
"/icons/icon-192.png",
"/icons/icon-512.png",
+ "/icons/event-192.png",
+ "/icons/event-512.png",
+ "/kodaira/events/today/",
];
self.addEventListener("install", (event) => {
@@ -49,6 +53,22 @@ self.addEventListener("fetch", (event) => {
return;
}
+ // アプリ用データ(data.json)は新しい内容を優先し、オフライン時はキャッシュを使う。
+ if (url.pathname === "/kodaira/events/data.json") {
+ event.respondWith(
+ fetch(request)
+ .then((response) => {
+ if (response.ok) {
+ const copy = response.clone();
+ caches.open(CACHE).then((cache) => cache.put(request, copy));
+ }
+ return response;
+ })
+ .catch(() => caches.match(request)),
+ );
+ return;
+ }
+
// それ以外はキャッシュ優先。取得できたらキャッシュを更新する。
event.respondWith(
caches.match(request).then((cached) => {