-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSw.js
More file actions
139 lines (135 loc) · 4.37 KB
/
Copy pathSw.js
File metadata and controls
139 lines (135 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Sw.js — service worker. Cache-first with network fallback.
// IMPORTANT: bump CACHE_VERSION on EVERY deploy or clients keep stale assets.
const CACHE_VERSION = "bloomspace-v37";
// App shell + heavy vendored deps. Web Awesome statically imports a graph of chunks from
// its loader and also lazy-loads component chunks on demand; that recursive chunk graph is
// cached at runtime by the fetch handler, not precached here. Full first-load-offline
// support (precaching the whole WA chunk graph) remains a runtime concern: the fetch
// handler caches each WA chunk on first use. All first-party modules ARE precached below —
// when you add a NEW Sim/Render/Ui module, add it here too. URLs stay relative for subpaths.
const SHELL = [
"./",
"Index.html",
"Main.js",
"Game.js",
"Manifest.webmanifest",
"Icons/Icon.svg",
"Ui/App.js",
"Ui/Hud.js",
"Ui/Overlay.js",
"Ui/Menus.js",
"Ui/Input.js",
"Ui/Sound.js",
"Ui/Persist.js",
"Ui/Tutorial.js",
"Audio/Send.wav",
"Audio/Capture.wav",
"Audio/Death.wav",
"Audio/Plant.wav",
"Audio/Fire.wav",
"Audio/Win.wav",
"Audio/Lose.wav",
"Audio/Alert.wav",
"Audio/Explosion.wav",
"Audio/Flare.wav",
"Audio/Meteor.wav",
"Audio/AmbientDeep.wav",
"Audio/AmbientShimmer.wav",
"Sim/World.js",
"Sim/Tech.js",
"Sim/MapGen.js",
"Sim/Moons.js",
"Sim/Seedlings.js",
"Sim/Combat.js",
"Sim/Economy.js",
"Sim/Trees.js",
"Sim/Bombard.js",
"Sim/Upgrade.js",
"Sim/Commands.js",
"Sim/Ai.js",
"Sim/Save.js",
"Sim/Hazards.js",
"Sim/Fog.js",
"Render/Scene.js",
"Render/SeedlingView.js",
"Render/AsteroidView.js",
"Render/EdgeLayer.js",
"Render/Preview.js",
"Render/ThreatView.js",
"Render/TreeView.js",
"Render/Fx.js",
"Render/Picking.js",
"Render/Palette.js",
"Render/Minimap.js",
"Render/Glyphs.js",
"Render/Theme.js",
"Vendor/Three/Three.module.js",
"Vendor/Three/Jsm/postprocessing/EffectComposer.js",
"Vendor/Three/Jsm/postprocessing/Pass.js",
"Vendor/Three/Jsm/postprocessing/RenderPass.js",
"Vendor/Three/Jsm/postprocessing/UnrealBloomPass.js",
"Vendor/Three/Jsm/postprocessing/OutputPass.js",
"Vendor/Three/Jsm/postprocessing/ShaderPass.js",
"Vendor/Three/Jsm/postprocessing/MaskPass.js",
"Vendor/Three/Jsm/shaders/CopyShader.js",
"Vendor/Three/Jsm/shaders/LuminosityHighPassShader.js",
"Vendor/Three/Jsm/shaders/OutputShader.js",
"Vendor/FontAwesome/Css/All.min.css",
"Vendor/FontAwesome/Webfonts/fa-solid-900.woff2",
"Vendor/FontAwesome/Webfonts/fa-regular-400.woff2",
"Vendor/FontAwesome/Webfonts/fa-brands-400.woff2",
"Vendor/WebAwesome/webawesome.loader.js",
"Vendor/WebAwesome/styles/webawesome.css",
];
self.addEventListener("install", (event) => {
event.waitUntil(
caches
.open(CACHE_VERSION)
.then((cache) =>
Promise.allSettled(
SHELL.map((u) => cache.add(new Request(u, { cache: "reload" }))),
),
)
.then(() => self.skipWaiting()),
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(
keys.filter((k) => k !== CACHE_VERSION).map((k) => caches.delete(k)),
),
)
.then(() => self.clients.claim()),
);
});
self.addEventListener("fetch", (event) => {
const req = event.request;
if (req.method !== "GET") return;
event.respondWith(
caches.match(req).then((cached) => {
if (cached) return cached;
return fetch(req)
.then((res) => {
// Runtime-cache same-origin GETs (e.g. Web Awesome's lazy chunks). status===200
// only; opaque/cross-origin and partial (206) responses are skipped.
if (res && res.status === 200) {
const copy = res.clone();
caches.open(CACHE_VERSION).then((c) => c.put(req, copy));
}
return res;
})
.catch(() =>
// Network failed (offline) and the resource wasn't cached above. For a navigation,
// boot the cached app shell so the PWA still launches; otherwise return an explicit
// 504 so respondWith never resolves to undefined (which surfaces as a confusing hard
// network error). `cached` is always undefined here — the cache hit returned at line 111.
req.mode === "navigate"
? caches.match("Index.html")
: new Response("", { status: 504, statusText: "Offline" }),
);
}),
);
});