mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-10 14:05:14 +00:00
feat: Add service worker with offline support and route caching to web dashboard
- Add offline.html fallback page with gradient background, centered container, and retry button - Add sw.js service worker with telecom-dashboard-v1 cache for dashboard routes - Add install event handler caching /, /login, /dashboard, /services, /monitoring, /deploy, /plugins, /automation, /chaos, /billing, and /config routes - Add fetch event handler with cache-first strategy and offline.html fallback - Add activate event
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const CACHE_NAME = 'telecom-dashboard-v1';
|
||||
const urlsToCache = [
|
||||
'/',
|
||||
'/login',
|
||||
'/dashboard',
|
||||
'/services',
|
||||
'/monitoring',
|
||||
'/deploy',
|
||||
'/plugins',
|
||||
'/automation',
|
||||
'/chaos',
|
||||
'/billing',
|
||||
'/config',
|
||||
];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then((cache) => {
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return fetch(event.request).catch(() => {
|
||||
return caches.match('/offline.html');
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cacheName) => {
|
||||
if (cacheName !== CACHE_NAME) {
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user