V1.1.2 //
-> Conversion du temps de retard pour >=60 Min -> Amélioration du rendu EVA (AFFICHEUR ABANDONNÉ PAR SNCF, Abandon possible) -> AFFICHAGE DE TOUTES LES DONNÉES EN MÊME TEMPS
This commit is contained in:
1 parent
23828a54ef
commit
8f00da0896
13 files changed
+1115
-270
No files matched your search
+46
-21
@@ -1,18 +1,6 @@
|
||||
const CACHE_NAME = 'ferrovia-pwa-v1';
|
||||
const CACHE_NAME = 'ferrovia-pwa-v2';
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
return cache.addAll([
|
||||
'./',
|
||||
'./index.html',
|
||||
'./manifest.json',
|
||||
'./favicon.ico',
|
||||
'./logo192.png',
|
||||
'./logo512.png'
|
||||
]);
|
||||
})
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
@@ -28,24 +16,61 @@ self.addEventListener('activate', (event) => {
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
// Ignorer les requêtes non-GET et les requêtes vers d'autres origines ou APIs
|
||||
if (event.request.method !== 'GET' || !event.request.url.startsWith(self.location.origin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pour la navigation (HTML / pages), stratégie Network-First systématique pour toujours charger la dernière version
|
||||
const isNavigation = event.request.mode === 'navigate' || (event.request.headers.get('accept') && event.request.headers.get('accept').includes('text/html'));
|
||||
|
||||
if (isNavigation) {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((networkResponse) => {
|
||||
if (networkResponse && networkResponse.ok) {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
||||
}
|
||||
return networkResponse;
|
||||
})
|
||||
.catch(() => {
|
||||
return caches.match(event.request).then((cached) => cached || caches.match('/index.html') || caches.match('./index.html'));
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pour les scripts JS et CSS, Network-First pour éviter le gel des bundles
|
||||
const isCodeAsset = event.request.url.includes('/static/js/') || event.request.url.includes('/static/css/');
|
||||
if (isCodeAsset) {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((networkResponse) => {
|
||||
if (networkResponse && networkResponse.ok) {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
||||
}
|
||||
return networkResponse;
|
||||
})
|
||||
.catch(() => {
|
||||
return caches.match(event.request);
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pour les autres ressources (images, favicons, polices), Cache-First avec mise en cache réseau
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((cachedResponse) => {
|
||||
if (cachedResponse) {
|
||||
return cachedResponse;
|
||||
}
|
||||
return fetch(event.request).then((networkResponse) => {
|
||||
return caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, networkResponse.clone());
|
||||
return networkResponse;
|
||||
});
|
||||
}).catch(() => {
|
||||
// En cas d'échec réseau total, on pourrait retourner un fallback hors-ligne
|
||||
return caches.match('./index.html');
|
||||
if (networkResponse && networkResponse.ok) {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
||||
}
|
||||
return networkResponse;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user