// LittleShop Admin - Service Worker // Provides offline functionality and app-like experience const CACHE_NAME = 'littleshop-admin-v1'; const urlsToCache = [ '/Admin/Dashboard', '/Admin/Orders', '/Admin/Products', '/Admin/Categories', '/lib/bootstrap/css/bootstrap.min.css', '/lib/fontawesome/css/all.min.css', '/lib/bootstrap-icons/bootstrap-icons.css', '/css/modern-admin.css', '/lib/jquery/jquery.min.js', '/lib/bootstrap/js/bootstrap.bundle.min.js', '/js/modern-mobile.js', '/lib/fontawesome/webfonts/fa-solid-900.woff2', '/lib/fontawesome/webfonts/fa-brands-400.woff2' ]; // Install event - cache resources self.addEventListener('install', (event) => { console.log('SW: Installing service worker'); event.waitUntil( caches.open(CACHE_NAME) .then((cache) => { console.log('SW: Caching app shell'); return cache.addAll(urlsToCache); }) ); }); // Activate event - clean up old caches self.addEventListener('activate', (event) => { console.log('SW: Activating service worker'); event.waitUntil( caches.keys().then((cacheNames) => { return Promise.all( cacheNames.map((cacheName) => { if (cacheName !== CACHE_NAME) { console.log('SW: Deleting old cache:', cacheName); return caches.delete(cacheName); } }) ); }) ); }); // Fetch event - serve from cache, fallback to network self.addEventListener('fetch', (event) => { // Only handle GET requests if (event.request.method !== 'GET') { return; } event.respondWith( caches.match(event.request) .then((response) => { // Return cached version or fetch from network return response || fetch(event.request).catch(() => { // If both cache and network fail, show offline page for HTML requests if (event.request.headers.get('accept').includes('text/html')) { return new Response(` LittleShop Admin - Offline
📱

You're offline

Please check your internet connection and try again.

Try Again `, { headers: { 'Content-Type': 'text/html' } }); } }); }) ); });