Skip to content

Commit cf65b65

Browse files
deploy: forge-realms slow/flaky-link launch fix (sw v24)
1 parent 6d3e54c commit cf65b65

5 files changed

Lines changed: 2351 additions & 3 deletions

File tree

site/forge-realms/assets/RtsScene-DKPBnc9l.js

Lines changed: 240 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/forge-realms/assets/game-DKwePmz4.js

Lines changed: 2080 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/forge-realms/assets/saveSync-D3L_5os0.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/forge-realms/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@
559559
transition: transform 160ms ease;
560560
}
561561

562+
.start-loading__retry {
563+
margin-top: 6px;
564+
justify-self: start;
565+
}
566+
562567
.menu-button {
563568
min-width: 136px;
564569
min-height: 46px;
@@ -681,7 +686,7 @@
681686
}
682687
}
683688
</style>
684-
<script type="module" crossorigin src="/forge-realms/assets/game-DPb26U3x.js"></script>
689+
<script type="module" crossorigin src="/forge-realms/assets/game-DKwePmz4.js"></script>
685690
<link rel="modulepreload" crossorigin href="/forge-realms/assets/rolldown-runtime-ciTZEWaI.js">
686691
<link rel="modulepreload" crossorigin href="/forge-realms/assets/modulepreload-polyfill-Cf3xff8G.js">
687692
<link rel="stylesheet" crossorigin href="/forge-realms/assets/game-CvEu7uRG.css">
@@ -809,6 +814,7 @@ <h2 class="start-loading__title">Preparing the battlefield</h2>
809814
<div class="start-loading__track" aria-hidden="true">
810815
<span class="start-loading__bar" id="start-loading-bar"></span>
811816
</div>
817+
<button type="button" class="menu-button menu-button--primary start-loading__retry" id="start-loading-retry" hidden>Try Again</button>
812818
</div>
813819
</div>
814820
</section>

site/forge-realms/sw.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const CACHE_NAME = "forge-realms-v23";
1+
const CACHE_NAME = "forge-realms-v24";
22
const CORE_ASSETS = ["", "index.html", "manifest.webmanifest", "icon.svg"].map((path) =>
33
new URL(path, self.registration.scope).toString(),
44
);
@@ -7,6 +7,27 @@ function isCacheableResponse(response) {
77
return response && response.ok;
88
}
99

10+
// Retry a genuinely failed network fetch a couple of times before giving up.
11+
// Booth/mobile links drop the odd request; without this a single dropped JS
12+
// chunk or atlas page rejects the dynamic import ("Could not start the realm")
13+
// or strands the artwork load with no second chance. Only thrown (transient)
14+
// failures retry — a real HTTP error response is returned as-is so a genuinely
15+
// missing asset still fails fast rather than looping.
16+
async function fetchWithRetry(request, attempts = 3) {
17+
let lastError;
18+
for (let attempt = 0; attempt < attempts; attempt += 1) {
19+
try {
20+
return await fetch(request);
21+
} catch (error) {
22+
lastError = error;
23+
if (attempt < attempts - 1) {
24+
await new Promise((resolve) => setTimeout(resolve, 300 * (attempt + 1)));
25+
}
26+
}
27+
}
28+
throw lastError;
29+
}
30+
1031
async function cacheSuccessfulResponse(cache, request, response) {
1132
if (isCacheableResponse(response)) {
1233
await cache.put(request, response.clone());
@@ -59,7 +80,7 @@ self.addEventListener("fetch", (event) => {
5980
if (cached) {
6081
await cache.delete(event.request);
6182
}
62-
return cacheSuccessfulResponse(cache, event.request, await fetch(event.request));
83+
return cacheSuccessfulResponse(cache, event.request, await fetchWithRetry(event.request));
6384
}),
6485
);
6586
});

0 commit comments

Comments
 (0)