This commit is contained in:
2026-04-29 07:39:29 +02:00
parent 41a5472582
commit b866845b6a
40 changed files with 71735 additions and 111 deletions

View File

@@ -3,26 +3,57 @@
"name": "RadioPlayer",
"short_name": "Radio",
"description": "RadioPlayer - stream and cast your favorite radio stations.",
"lang": "en",
"dir": "ltr",
"start_url": "./",
"scope": ".",
"display": "standalone",
"display_override": ["window-controls-overlay", "standalone", "minimal-ui", "browser"],
"display": "fullscreen",
"display_override": ["fullscreen", "window-controls-overlay", "standalone", "minimal-ui", "browser"],
"orientation": "portrait-primary",
"background_color": "#111318",
"theme_color": "#111318",
"prefer_related_applications": false,
"categories": ["music", "entertainment"],
"screenshots": [
{
"src": "screenshots/radioplayer-desktop.png",
"sizes": "2520x1792",
"type": "image/png",
"form_factor": "wide",
"label": "RadioPlayer desktop player and station library"
},
{
"src": "screenshots/radioplayer-mobile.png",
"sizes": "683x1477",
"type": "image/png",
"form_factor": "narrow",
"label": "RadioPlayer mobile player and station library"
}
],
"icons": [
{
"src": "assets/radioplayer-logo-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
"purpose": "any"
},
{
"src": "assets/radioplayer-logo-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
"purpose": "any"
},
{
"src": "assets/radioplayer-logo-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "assets/radioplayer-logo-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"shortcuts": [

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

View File

@@ -929,71 +929,767 @@
"metadata": {}
},
{
"id": "us-kexp",
"name": "KEXP 90.3",
"id": "si-netfm",
"name": "Radio NET FM",
"slogan": "",
"category": "Alternative",
"country": "US",
"language": "en",
"region": "International",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Maribor",
"tags": [
"indie",
"alternative",
"public"
"music",
"international",
"traffic"
],
"website": "https://www.kexp.org/",
"website": "https://www.radionet.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://kexp.streamguys1.com/kexp160.aac"
"audio": "https://stream.radionet.si/stream.ogg"
},
"metadata": {}
},
{
"id": "uk-nts-1",
"name": "NTS Radio 1",
"id": "capris-live",
"name": "Radio Capris LIVE",
"slogan": "",
"category": "Electronic",
"country": "GB",
"language": "en",
"region": "International",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"underground",
"electronic",
"experimental"
"capris",
"live",
"hits"
],
"website": "https://www.nts.live/",
"website": "https://www.radiocapris.si/si/onair/live",
"enabled": true,
"assets": {
"logo": ""
"logo": "https://www.radiocapris.si/data/images/streams/live.png?t=3"
},
"streams": {
"audio": "https://stream-relay-geo.ntslive.net/stream?client=direct"
"audio": "http://stream.exit.si/live"
},
"metadata": {}
},
{
"id": "uk-nts-2",
"name": "NTS Radio 2",
"id": "capris-cafe",
"name": "Radio Capris CAFE",
"slogan": "",
"category": "Electronic",
"country": "GB",
"language": "en",
"region": "International",
"category": "Chill",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"underground",
"electronic",
"experimental"
"capris",
"cafe",
"chill",
"lounge"
],
"website": "https://www.nts.live/",
"website": "https://www.radiocapris.si/si/onair/cafe",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/cafe.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/CAFE"
},
"metadata": {}
},
{
"id": "capris-ibiza",
"name": "Radio Capris IBIZA",
"slogan": "",
"category": "Dance",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"ibiza",
"dance",
"electronic"
],
"website": "https://www.radiocapris.si/si/onair/ibiza",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/ibiza.png?t=4"
},
"streams": {
"audio": "http://stream.exit.si/IBIZA"
},
"metadata": {}
},
{
"id": "capris-hits",
"name": "Radio Capris HITS",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"hits",
"pop"
],
"website": "https://www.radiocapris.si/si/onair/hits",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/hits.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/HITS"
},
"metadata": {}
},
{
"id": "capris-80",
"name": "Radio Capris 80'",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"80s",
"retro"
],
"website": "https://www.radiocapris.si/si/onair/80",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/80.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/80"
},
"metadata": {}
},
{
"id": "capris-dalmacija",
"name": "Radio Capris DALMACIJA",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"dalmacija",
"croatian"
],
"website": "https://www.radiocapris.si/si/onair/dalmacija",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/dalmacija.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/DALMACIJA"
},
"metadata": {}
},
{
"id": "capris-exyu",
"name": "Radio Capris EXYU",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"exyu",
"balkan"
],
"website": "https://www.radiocapris.si/si/onair/exyu",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/exyu.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/EXYU"
},
"metadata": {}
},
{
"id": "capris-love",
"name": "Radio Capris LOVE",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"love",
"ballads"
],
"website": "https://www.radiocapris.si/si/onair/love",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/love.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/LOVE"
},
"metadata": {}
},
{
"id": "capris-spomini",
"name": "Radio Capris SPOMINI",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"spomini",
"oldies"
],
"website": "https://www.radiocapris.si/si/onair/spomini",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/spomini.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/SPOMINI"
},
"metadata": {}
},
{
"id": "capris-rock",
"name": "Radio Capris ROCK",
"slogan": "",
"category": "Rock",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"rock"
],
"website": "https://www.radiocapris.si/si/onair/rock",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/rock.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/ROCK"
},
"metadata": {}
},
{
"id": "capris-poletje",
"name": "Radio Capris POLETJE",
"slogan": "",
"category": "Seasonal",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"summer",
"poletje"
],
"website": "https://www.radiocapris.si/si/onair/poletje",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/poletje.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/POLETJE"
},
"metadata": {}
},
{
"id": "capris-no1",
"name": "Radio Capris NUMBER 1's",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"number-one",
"hits"
],
"website": "https://www.radiocapris.si/si/onair/no1",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/no1.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/NO1"
},
"metadata": {}
},
{
"id": "capris-90-pop",
"name": "Radio Capris 90's POP",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"90s",
"pop"
],
"website": "https://www.radiocapris.si/si/onair/90",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/90.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/90"
},
"metadata": {}
},
{
"id": "capris-megamix",
"name": "Radio Capris 90's DANCE / MEGAMIX",
"slogan": "",
"category": "Dance",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"90s",
"dance",
"megamix"
],
"website": "https://www.radiocapris.si/si/onair/megamix",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/megamix.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/MEGAMIX"
},
"metadata": {}
},
{
"id": "capris-inthemix",
"name": "Radio Capris IN THE MIX",
"slogan": "",
"category": "Dance",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"mix",
"dance"
],
"website": "https://www.radiocapris.si/si/onair/inthemix",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/inthemix.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/INTHEMIX"
},
"metadata": {}
},
{
"id": "capris-club",
"name": "Radio Capris CLUB",
"slogan": "",
"category": "Dance",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"club",
"dance"
],
"website": "https://www.radiocapris.si/si/onair/club",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/club.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/CLUB"
},
"metadata": {}
},
{
"id": "capris-ita",
"name": "Radio Capris ITALIJA",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"italian",
"ita"
],
"website": "https://www.radiocapris.si/si/onair/ita",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/ita.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/ITA"
},
"metadata": {}
},
{
"id": "capris-slo",
"name": "Radio Capris SLOVENIJA",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"slovenian",
"slo"
],
"website": "https://www.radiocapris.si/si/onair/slo",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/slo.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/SLO"
},
"metadata": {}
},
{
"id": "capris-istra",
"name": "Radio Capris ISTRA",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"istra",
"local"
],
"website": "https://www.radiocapris.si/si/onair/istra",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/istra.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/ISTRA"
},
"metadata": {}
},
{
"id": "capris-xmas",
"name": "Radio Capris XMAS",
"slogan": "",
"category": "Seasonal",
"country": "SI",
"language": "sl",
"region": "Koper",
"tags": [
"capris",
"xmas",
"christmas",
"seasonal"
],
"website": "https://www.radiocapris.si/si/onair/xmas",
"enabled": true,
"assets": {
"logo": "https://www.radiocapris.si/data/images/streams/xmas.png?t=3"
},
"streams": {
"audio": "http://stream.exit.si/XMAS"
},
"metadata": {}
},
{
"id": "hitradio-center",
"name": "Hitradio Center",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"hits",
"pop"
],
"website": "https://www.radiocenter.si/live/hitradio-center",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream-relay-geo.ntslive.net/stream2?client=direct"
"audio": "https://stream2.nextmedia.si/hls/hrc/live.m3u8"
},
"metadata": {}
},
{
"id": "hitradio-center-top-100",
"name": "Center Top 100",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"top-100",
"hits"
],
"website": "https://www.radiocenter.si/live/center-top-100",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream.nextmedia.si/proxy/centerhit4?mp=/stream?oid=hrcweb"
},
"metadata": {}
},
{
"id": "hitradio-center-fresh-pop",
"name": "Center Fresh Pop",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"fresh-pop",
"pop"
],
"website": "https://www.radiocenter.si/live/center-fresh-pop",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream.nextmedia.si/proxy/centerpop4?mp=/stream"
},
"metadata": {}
},
{
"id": "hitradio-center-in-the-mix",
"name": "Center In The Mix / Megamix",
"slogan": "",
"category": "Dance",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"mix",
"megamix",
"dance"
],
"website": "https://www.radiocenter.si/live/center-megamix/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream.nextmedia.si/proxy/centermix4?mp=/stream"
},
"metadata": {}
},
{
"id": "hitradio-center-80s",
"name": "Center 80's X",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"80s",
"retro"
],
"website": "https://www.radiocenter.si/live/center-80s",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream2.nextmedia.si/hls/gex/live.m3u8?sid=1777222063788516308"
},
"metadata": {}
},
{
"id": "hitradio-center-latin",
"name": "Center Latin",
"slogan": "",
"category": "Latin",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"latin"
],
"website": "https://stream.nextmedia.si/proxy/center_latin?mp=/center",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "http://stream3.radiocenter.si:8200/;stream/1"
},
"metadata": {}
},
{
"id": "hitradio-center-love",
"name": "Center Love",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"love",
"ballads"
],
"website": "https://www.radiocenter.si/live/center-love",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream.nextmedia.si/proxy/centerlove4?mp=/stream"
},
"metadata": {}
},
{
"id": "hitradio-center-yu",
"name": "Center YU",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"yu",
"retro"
],
"website": "https://www.radiocenter.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream2.nextmedia.si/hls/jub/live.m3u8?sid=1777222063788516308"
},
"metadata": {}
},
{
"id": "hitradio-center-gen-x",
"name": "Center Gen X",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"international",
"retro"
],
"website": "https://www.radiocenter.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream2.nextmedia.si/hls/gex/128k/gex-128.m3u8?sid=1777222063788516308"
},
"metadata": {}
},
{
"id": "hitradio-enter-radio",
"name": "Center Enter Radio",
"slogan": "",
"category": "Retro",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"center",
"international",
"retro"
],
"website": "https://www.radiocenter.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream2.nextmedia.si/hls/ent/live.m3u8?sid=1777222063788516308"
},
"metadata": {}
},
{
"id": "si-radio-city",
"name": "Radio City",
"slogan": "",
"category": "Regional",
"country": "SI",
"language": "sl",
"region": "Maribor",
"tags": [
"radio-city",
"maribor",
"pop",
"hits",
"local"
],
"website": "https://radiocity.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream1.radiocity.si/CityMp3128.mp3"
},
"metadata": {}
},
{
"id": "si-radio-ekspres",
"name": "Radio Exspres",
"slogan": "",
"category": "Pop",
"country": "SI",
"language": "sl",
"region": "National",
"tags": [
"ekspres",
"pop",
"hits",
"slovenia"
],
"website": "https://www.radioekspres.si/",
"enabled": true,
"assets": {
"logo": ""
},
"streams": {
"audio": "https://stream.nextmedia.si/proxy/ekspres1?mp=/stream"
},
"metadata": {}
}

View File

@@ -1,21 +1,104 @@
// NOTE: This service worker is for the web/PWA build.
// For development we aggressively unregister SWs in `src/player.js`.
//
// Bump this value whenever caching logic changes to guarantee clients don't
// keep an old UI after updates.
const CACHE_NAME = 'radioplayer-pwa-v4';
// This value is rewritten automatically before each build so deployed clients
// refresh to the newest shell and cached assets.
const CACHE_NAME = 'radioplayer-pwa-v5-1777404493334';
const CORE_ASSETS = [
'./',
'index.html',
'privacy.html',
'data/radio-stations.json',
'stations.json',
'manifest.json',
'images/radio-placeholder.svg',
'assets/radioplayer-logo-192.png',
'assets/radioplayer-logo-512.png',
];
const CORE_PATHS = new Set(CORE_ASSETS.map((p) => new URL(p, self.registration.scope).pathname));
const DATA_PATHS = new Set([
new URL('data/radio-stations.json', self.registration.scope).pathname,
new URL('stations.json', self.registration.scope).pathname,
new URL('manifest.json', self.registration.scope).pathname,
]);
const IMAGE_FALLBACK_PATH = new URL('images/radio-placeholder.svg', self.registration.scope).pathname;
function isCacheableResponse(response) {
return Boolean(response && response.ok && response.type === 'basic');
}
async function putInCache(request, response) {
if (!isCacheableResponse(response)) return;
const cache = await caches.open(CACHE_NAME);
await cache.put(request, response.clone());
}
async function precacheBuiltAssets(cache) {
try {
const indexResp = await fetch(new Request('./', { cache: 'reload' }));
if (isCacheableResponse(indexResp)) {
await cache.put('./', indexResp.clone());
}
const indexText = await indexResp.text();
const assetUrls = [...indexText.matchAll(/(?:src|href)="([^"]+)"/g)]
.map((match) => match[1])
.filter((assetPath) => assetPath.startsWith('./assets/') || assetPath.startsWith('assets/'))
.map((assetPath) => new URL(assetPath, self.registration.scope).href);
await Promise.allSettled(assetUrls.map(async (assetUrl) => {
const assetResp = await fetch(new Request(assetUrl, { cache: 'reload' }));
if (!isCacheableResponse(assetResp)) return;
await cache.put(assetUrl, assetResp);
}));
} catch (e) {
// If HTML parsing fails, runtime caching below still catches assets.
}
}
async function networkFirst(request, fallbackRequest) {
try {
const networkResp = await fetch(request);
await putInCache(request, networkResp);
return networkResp;
} catch (error) {
const cached = await caches.match(request);
if (cached) return cached;
if (fallbackRequest) {
const fallback = await caches.match(fallbackRequest);
if (fallback) return fallback;
}
throw error;
}
}
async function staleWhileRevalidate(request, fallbackRequest) {
const cached = await caches.match(request);
const networkPromise = fetch(request)
.then(async (networkResp) => {
await putInCache(request, networkResp);
return networkResp;
})
.catch(async () => {
if (fallbackRequest) {
const fallback = await caches.match(fallbackRequest);
if (fallback) return fallback;
}
return null;
});
if (cached) {
return cached;
}
const networkResp = await networkPromise;
if (networkResp) return networkResp;
return new Response('', { status: 503, statusText: 'Service Unavailable' });
}
self.addEventListener('install', (event) => {
// Activate updated SW as soon as it's installed.
@@ -23,26 +106,15 @@ self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then(async (cache) => {
const reqs = CORE_ASSETS.map((p) => new Request(p, { cache: 'reload' }));
await cache.addAll(reqs);
await Promise.allSettled(reqs.map(async (request) => {
const response = await fetch(request);
if (!isCacheableResponse(response)) return;
await cache.put(request, response);
}));
// Vite fingerprints JS/CSS assets in production. Parse the built HTML so
// the installed PWA can launch offline after its first install.
try {
const indexResp = await fetch(new Request('./', { cache: 'reload' }));
const indexText = await indexResp.clone().text();
await cache.put('./', indexResp);
const assetUrls = [...indexText.matchAll(/(?:src|href)="([^"]+)"/g)]
.map((match) => match[1])
.filter((assetPath) => assetPath.startsWith('./assets/') || assetPath.startsWith('assets/'))
.map((assetPath) => new URL(assetPath, self.registration.scope).href);
await Promise.all(assetUrls.map((assetUrl) => {
return cache.add(new Request(assetUrl, { cache: 'reload' })).catch(() => {});
}));
} catch (e) {
// If HTML parsing fails, runtime caching below still catches assets.
}
await precacheBuiltAssets(cache);
})
);
});
@@ -61,6 +133,7 @@ self.addEventListener('activate', (event) => {
self.addEventListener('fetch', (event) => {
// Only handle GET requests
if (event.request.method !== 'GET') return;
if (event.request.headers.has('range')) return;
const url = new URL(event.request.url);
@@ -70,37 +143,46 @@ self.addEventListener('fetch', (event) => {
}
const isCore = CORE_PATHS.has(url.pathname);
const isDataRequest = DATA_PATHS.has(url.pathname);
const isHtmlNavigation = event.request.mode === 'navigate' || (event.request.headers.get('accept') || '').includes('text/html');
const isStaticAsset = ['script', 'style', 'font', 'worker'].includes(event.request.destination)
|| url.pathname.includes('/assets/');
const isImage = event.request.destination === 'image';
if (url.pathname.endsWith('/sw.js')) {
return;
}
// Network-first for navigations and core assets to prevent "old UI" issues.
if (isHtmlNavigation || isCore) {
if (isHtmlNavigation) {
event.respondWith(
fetch(event.request)
.then((networkResp) => {
const respClone = networkResp.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, respClone)).catch(() => {});
return networkResp;
})
.catch(() => caches.match(event.request).then((cached) => cached || caches.match('./') || caches.match('index.html')))
networkFirst(event.request, './').catch(
() => caches.match('./') || caches.match('index.html') || new Response('', { status: 503, statusText: 'Offline' })
)
);
return;
}
if (isCore || isDataRequest) {
event.respondWith(
networkFirst(event.request).catch(
() => caches.match(event.request) || new Response('', { status: 503, statusText: 'Offline' })
)
);
return;
}
if (isStaticAsset) {
event.respondWith(staleWhileRevalidate(event.request));
return;
}
if (isImage) {
event.respondWith(staleWhileRevalidate(event.request, IMAGE_FALLBACK_PATH));
return;
}
event.respondWith(
caches.match(event.request).then((cached) => {
if (cached) return cached;
return fetch(event.request).then((networkResp) => {
// Optionally cache new resources (best-effort)
try {
const respClone = networkResp.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, respClone)).catch(()=>{});
} catch (e) {}
return networkResp;
}).catch(() => {
// If offline and HTML navigation, return cached index.html
if (event.request.mode === 'navigate') return caches.match('./') || caches.match('index.html');
return new Response('', { status: 503, statusText: 'Service Unavailable' });
});
})
staleWhileRevalidate(event.request)
);
});