summaryrefslogtreecommitdiffhomepage
path: root/public
diff options
context:
space:
mode:
authorYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-11-17 23:37:08 +0900
committerYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-11-17 23:37:08 +0900
commit5216789b90514001fcf5e5f64c644374242ed196 (patch)
tree6182c610f46416bb53734b8fcad67f79fabd4af0 /public
parent641e02c7968930ad67248b36fa5ba9558d0adcbf (diff)
sw.js: アプリ画面とイベントデータをキャッシュ対象に追加
イベントページにイベント用のmanifestとapple-touch-iconを指定し、今日の予定の画面とdata.jsonをキャッシュするようにした。noindexのアプリ画面はサイトマップから除外した。
Diffstat (limited to 'public')
-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) => {