Merge branch 'fix/network-main-parity' into main (resolve conflicts)

This commit is contained in:
Nate Emmert committed 2026-03-17 14:21:49 -04:00
commit 49b54e0fe4
22 files changed
+11297 -2079

No files matched your search

+1246 -694
View File
File diff suppressed because it is too large. Load diff
+972 -154
View File
File diff suppressed because it is too large. Load diff
+1908 -849
View File
File diff suppressed because it is too large. Load diff
+15 -48
View File
@@ -1,12 +1,16 @@
'use strict';
const CACHE = 'weather-v4';
self.addEventListener('message', event => {
if (event.data === 'skipWaiting') self.skipWaiting();
});
// App shell — cached on install for offline use
const CACHE = 'weather-v5';
// App shell cached on install for offline resilience.
const PRECACHE = [
'/',
'/app.js?v=4',
'/style.css?v=4',
'/app.js',
'/style.css',
'/manifest.json',
'/icons/icon.svg'
];
@@ -22,9 +26,7 @@ self.addEventListener('install', event => {
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys()
.then(keys => Promise.all(
keys.filter(k => k !== CACHE).map(k => caches.delete(k))
))
.then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))))
.then(() => self.clients.claim())
);
});
@@ -33,7 +35,7 @@ self.addEventListener('fetch', event => {
const { request } = event;
const url = new URL(request.url);
// Skip non-GET, API calls, and map/radar tile requests
// Never intercept API/tile traffic.
if (
request.method !== 'GET' ||
url.pathname.startsWith('/api/') ||
@@ -45,14 +47,14 @@ self.addEventListener('fetch', event => {
return;
}
const isAppShellRequest =
const isShell =
request.mode === 'navigate' ||
request.destination === 'document' ||
request.destination === 'script' ||
request.destination === 'style';
// Prefer fresh app shell assets so UI updates are visible immediately.
if (isAppShellRequest) {
if (isShell) {
// Network-first keeps app updates fresh; cache as fallback.
event.respondWith(
fetch(request)
.then(response => {
@@ -67,11 +69,11 @@ self.addEventListener('fetch', event => {
return;
}
// Cache-first for static assets.
event.respondWith(
caches.match(request).then(cached => {
if (cached) return cached;
return fetch(request).then(response => {
// Only cache successful same-origin and trusted CDN responses
if (response.ok && (
url.origin === self.location.origin ||
url.hostname.includes('googleapis') ||
@@ -85,39 +87,4 @@ self.addEventListener('fetch', event => {
});
})
);
});
self.addEventListener('push', event => {
let payload = { title: 'Weather alert', body: 'New weather update available.', url: '/' };
try {
const data = event.data ? event.data.json() : null;
if (data) payload = { ...payload, ...data };
} catch {
// Ignore malformed payload and use defaults.
}
event.waitUntil(
self.registration.showNotification(payload.title, {
body: payload.body,
icon: '/icons/icon.svg',
badge: '/icons/icon.svg',
data: { url: payload.url || '/' },
})
);
});
self.addEventListener('notificationclick', event => {
event.notification.close();
const target = event.notification?.data?.url || '/';
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(windowClients => {
const existing = windowClients.find(c => c.url.includes(self.location.origin));
if (existing) {
existing.focus();
existing.navigate(target);
return;
}
return clients.openWindow(target);
})
);
});
});