mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
Disable stale dashboard service worker cache
This commit is contained in:
125
static/sw.js
125
static/sw.js
@@ -1,122 +1,13 @@
|
|||||||
/* INTERCEPT Service Worker — cache-first static, network-only for API/SSE/WS */
|
/* INTERCEPT Service Worker disabled to avoid stale cached static assets. */
|
||||||
const CACHE_NAME = 'intercept-v3';
|
self.addEventListener('install', () => {
|
||||||
|
|
||||||
const NETWORK_ONLY_PREFIXES = [
|
|
||||||
'/stream', '/ws/', '/api/', '/gps/', '/wifi/', '/bluetooth/',
|
|
||||||
'/adsb/', '/ais/', '/acars/', '/aprs/', '/tscm/', '/satellite/',
|
|
||||||
'/meshtastic/', '/bt_locate/', '/receiver/', '/sensor/', '/pager/',
|
|
||||||
'/sstv/', '/weather-sat/', '/subghz/', '/rtlamr/', '/dsc/', '/vdl2/',
|
|
||||||
'/spy/', '/space-weather/', '/websdr/', '/analytics/', '/correlation/',
|
|
||||||
'/recordings/', '/controller/', '/ops/',
|
|
||||||
];
|
|
||||||
|
|
||||||
const STATIC_PREFIXES = [
|
|
||||||
'/static/css/',
|
|
||||||
'/static/js/',
|
|
||||||
'/static/icons/',
|
|
||||||
'/static/fonts/',
|
|
||||||
];
|
|
||||||
|
|
||||||
const CACHE_EXACT = ['/manifest.json'];
|
|
||||||
|
|
||||||
function isHttpRequest(req) {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isNetworkOnly(req) {
|
|
||||||
if (req.method !== 'GET') return true;
|
|
||||||
const accept = req.headers.get('Accept') || '';
|
|
||||||
if (accept.includes('text/event-stream')) return true;
|
|
||||||
const url = new URL(req.url);
|
|
||||||
return NETWORK_ONLY_PREFIXES.some(p => url.pathname.startsWith(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
function isStaticAsset(req) {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
if (CACHE_EXACT.includes(url.pathname)) return true;
|
|
||||||
return STATIC_PREFIXES.some(p => url.pathname.startsWith(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
function fallbackResponse(req, status = 503) {
|
|
||||||
const accept = req.headers.get('Accept') || '';
|
|
||||||
if (accept.includes('application/json')) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ status: 'error', message: 'Network unavailable' }),
|
|
||||||
{
|
|
||||||
status,
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accept.includes('text/event-stream')) {
|
|
||||||
return new Response('', {
|
|
||||||
status,
|
|
||||||
headers: { 'Content-Type': 'text/event-stream' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response('Offline', {
|
|
||||||
status,
|
|
||||||
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addEventListener('install', (e) => {
|
|
||||||
self.skipWaiting();
|
self.skipWaiting();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('activate', (e) => {
|
self.addEventListener('activate', (event) => {
|
||||||
e.waitUntil(
|
event.waitUntil(
|
||||||
caches.keys().then(keys =>
|
caches.keys()
|
||||||
Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
|
.then((keys) => Promise.all(keys.filter((key) => key.startsWith('intercept-')).map((key) => caches.delete(key))))
|
||||||
).then(() => self.clients.claim())
|
.then(() => self.registration.unregister())
|
||||||
);
|
.then(() => self.clients.claim())
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('fetch', (e) => {
|
|
||||||
const req = e.request;
|
|
||||||
|
|
||||||
// Ignore non-HTTP(S) requests so extensions/browser-internal URLs are untouched.
|
|
||||||
if (!isHttpRequest(req)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always bypass service worker for non-GET and streaming routes
|
|
||||||
if (isNetworkOnly(req)) {
|
|
||||||
e.respondWith(
|
|
||||||
fetch(req).catch(() => fallbackResponse(req, 503))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache-first for static assets
|
|
||||||
if (isStaticAsset(req)) {
|
|
||||||
e.respondWith(
|
|
||||||
caches.open(CACHE_NAME).then(cache =>
|
|
||||||
cache.match(req).then(cached => {
|
|
||||||
if (cached) {
|
|
||||||
// Revalidate in background
|
|
||||||
fetch(req).then(res => {
|
|
||||||
if (res && res.status === 200) cache.put(req, res.clone());
|
|
||||||
}).catch(() => {});
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
return fetch(req).then(res => {
|
|
||||||
if (res && res.status === 200) cache.put(req, res.clone());
|
|
||||||
return res;
|
|
||||||
}).catch(() => fallbackResponse(req, 504));
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Network-first for HTML pages
|
|
||||||
e.respondWith(
|
|
||||||
fetch(req).catch(() =>
|
|
||||||
caches.match(req).then(cached => cached || new Response('Offline', { status: 503 }))
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,6 +21,20 @@
|
|||||||
window.INTERCEPT_ADSB_AUTO_START = {{ adsb_auto_start | tojson }};
|
window.INTERCEPT_ADSB_AUTO_START = {{ adsb_auto_start | tojson }};
|
||||||
window.INTERCEPT_DEFAULT_LAT = {{ default_latitude | tojson }};
|
window.INTERCEPT_DEFAULT_LAT = {{ default_latitude | tojson }};
|
||||||
window.INTERCEPT_DEFAULT_LON = {{ default_longitude | tojson }};
|
window.INTERCEPT_DEFAULT_LON = {{ default_longitude | tojson }};
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.getRegistrations()
|
||||||
|
.then((registrations) => Promise.all(registrations.map((registration) => registration.unregister())))
|
||||||
|
.catch(() => {});
|
||||||
|
if ('caches' in window) {
|
||||||
|
caches.keys()
|
||||||
|
.then((keys) => Promise.all(
|
||||||
|
keys.filter((key) => key.startsWith('intercept-')).map((key) => caches.delete(key))
|
||||||
|
))
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script defer src="{{ url_for('static', filename='vendor/leaflet/leaflet.js') }}"></script>
|
<script defer src="{{ url_for('static', filename='vendor/leaflet/leaflet.js') }}"></script>
|
||||||
<script defer src="{{ url_for('static', filename='js/core/observer-location.js') }}"></script>
|
<script defer src="{{ url_for('static', filename='js/core/observer-location.js') }}"></script>
|
||||||
|
|||||||
@@ -16337,11 +16337,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- PWA Service Worker Registration -->
|
<!-- Disable legacy static-asset service worker to avoid stale dashboard JS/CSS -->
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker.register('/static/sw.js').catch(() => {});
|
navigator.serviceWorker.getRegistrations()
|
||||||
|
.then((registrations) => Promise.all(registrations.map((registration) => registration.unregister())))
|
||||||
|
.catch(() => {});
|
||||||
|
if ('caches' in window) {
|
||||||
|
caches.keys()
|
||||||
|
.then((keys) => Promise.all(
|
||||||
|
keys.filter((key) => key.startsWith('intercept-')).map((key) => caches.delete(key))
|
||||||
|
))
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Initialize global core modules after page load
|
// Initialize global core modules after page load
|
||||||
|
|||||||
@@ -18,6 +18,20 @@
|
|||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/satellite_dashboard.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/satellite_dashboard.css') }}">
|
||||||
<script>
|
<script>
|
||||||
window.INTERCEPT_SHARED_OBSERVER_LOCATION = {{ shared_observer_location | tojson }};
|
window.INTERCEPT_SHARED_OBSERVER_LOCATION = {{ shared_observer_location | tojson }};
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.getRegistrations()
|
||||||
|
.then((registrations) => Promise.all(registrations.map((registration) => registration.unregister())))
|
||||||
|
.catch(() => {});
|
||||||
|
if ('caches' in window) {
|
||||||
|
caches.keys()
|
||||||
|
.then((keys) => Promise.all(
|
||||||
|
keys.filter((key) => key.startsWith('intercept-')).map((key) => caches.delete(key))
|
||||||
|
))
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="{{ url_for('static', filename='js/core/observer-location.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/core/observer-location.js') }}"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user