stellar-drive 1.1.18 → 1.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/install-pwa.js +1 -1
- package/dist/sw/sw.js +46 -5
- package/package.json +1 -1
package/dist/bin/install-pwa.js
CHANGED
package/dist/sw/sw.js
CHANGED
|
@@ -256,6 +256,22 @@ function isStaticAsset(pathname) {
|
|
|
256
256
|
*/
|
|
257
257
|
async function handleNavigationRequest(request) {
|
|
258
258
|
const cache = await caches.open(SHELL_CACHE);
|
|
259
|
+
/* Offline fast path: skip the network entirely when we know we're offline.
|
|
260
|
+
This eliminates the 3-second timeout delay on iOS PWA in airplane mode,
|
|
261
|
+
where fetch() hangs instead of rejecting promptly. */
|
|
262
|
+
if (!self.navigator.onLine) {
|
|
263
|
+
console.log('[SW] Navigation offline (fast path), serving cache');
|
|
264
|
+
const cached = await cache.match('/');
|
|
265
|
+
if (cached)
|
|
266
|
+
return cached;
|
|
267
|
+
const offlinePage = await cache.match('/offline.html');
|
|
268
|
+
if (offlinePage)
|
|
269
|
+
return offlinePage;
|
|
270
|
+
return new Response(getOfflineHTML(), {
|
|
271
|
+
status: 200,
|
|
272
|
+
headers: { 'Content-Type': 'text/html; charset=utf-8' }
|
|
273
|
+
});
|
|
274
|
+
}
|
|
259
275
|
try {
|
|
260
276
|
/* 3-second timeout — don't leave the user staring at a blank screen */
|
|
261
277
|
const controller = new AbortController();
|
|
@@ -309,9 +325,17 @@ async function handleImmutableAsset(request) {
|
|
|
309
325
|
if (cached) {
|
|
310
326
|
return cached;
|
|
311
327
|
}
|
|
312
|
-
/*
|
|
328
|
+
/* Offline fast path: don't even try the network when offline */
|
|
329
|
+
if (!self.navigator.onLine) {
|
|
330
|
+
console.error('[SW] Immutable asset not cached and offline:', request.url);
|
|
331
|
+
return new Response('Asset not available offline', { status: 503 });
|
|
332
|
+
}
|
|
333
|
+
/* Not cached yet — fetch from network with 3s timeout and cache for next time */
|
|
313
334
|
try {
|
|
314
|
-
const
|
|
335
|
+
const controller = new AbortController();
|
|
336
|
+
const timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
337
|
+
const response = await fetch(request, { signal: controller.signal });
|
|
338
|
+
clearTimeout(timeoutId);
|
|
315
339
|
if (response.ok) {
|
|
316
340
|
cache.put(request, response.clone());
|
|
317
341
|
}
|
|
@@ -343,9 +367,16 @@ async function handleStaticAsset(request) {
|
|
|
343
367
|
if (cached) {
|
|
344
368
|
return cached;
|
|
345
369
|
}
|
|
346
|
-
/*
|
|
370
|
+
/* Offline fast path: don't try the network when offline */
|
|
371
|
+
if (!self.navigator.onLine) {
|
|
372
|
+
return new Response('Asset not available offline', { status: 503 });
|
|
373
|
+
}
|
|
374
|
+
/* Not cached — fetch with 3s timeout and store (only cache successful responses) */
|
|
347
375
|
try {
|
|
348
|
-
const
|
|
376
|
+
const controller = new AbortController();
|
|
377
|
+
const timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
378
|
+
const response = await fetch(request, { signal: controller.signal });
|
|
379
|
+
clearTimeout(timeoutId);
|
|
349
380
|
if (response.ok) {
|
|
350
381
|
cache.put(request, response.clone());
|
|
351
382
|
}
|
|
@@ -373,8 +404,18 @@ async function handleStaticAsset(request) {
|
|
|
373
404
|
*/
|
|
374
405
|
async function handleOtherRequest(request) {
|
|
375
406
|
const cache = await caches.open(SHELL_CACHE);
|
|
407
|
+
/* Offline fast path: go straight to cache when offline */
|
|
408
|
+
if (!self.navigator.onLine) {
|
|
409
|
+
const cached = await cache.match(request);
|
|
410
|
+
if (cached)
|
|
411
|
+
return cached;
|
|
412
|
+
return new Response('Offline', { status: 503 });
|
|
413
|
+
}
|
|
376
414
|
try {
|
|
377
|
-
const
|
|
415
|
+
const controller = new AbortController();
|
|
416
|
+
const timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
417
|
+
const response = await fetch(request, { signal: controller.signal });
|
|
418
|
+
clearTimeout(timeoutId);
|
|
378
419
|
if (response.ok) {
|
|
379
420
|
cache.put(request, response.clone());
|
|
380
421
|
}
|