generated from nhcarrigan/template
feat: Multiple Features, Accessibility, Security, and UX Improvements #59
@@ -11,11 +11,6 @@ const IMAGE_CACHE = `${CACHE_VERSION}-images`;
|
||||
|
||||
// Static assets to cache on install
|
||||
const STATIC_ASSETS = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/main.js',
|
||||
'/runtime.js',
|
||||
'/styles.css',
|
||||
'/offline.html'
|
||||
];
|
||||
|
||||
@@ -27,6 +22,8 @@ self.addEventListener('install', (event) => {
|
||||
console.log('[Service Worker] Caching static assets');
|
||||
return cache.addAll(STATIC_ASSETS).catch((err) => {
|
||||
console.error('[Service Worker] Failed to cache static assets:', err);
|
||||
// Don't fail installation if caching fails
|
||||
return Promise.resolve();
|
||||
});
|
||||
}).then(() => {
|
||||
return self.skipWaiting();
|
||||
@@ -137,10 +134,13 @@ self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(
|
||||
fetch(request)
|
||||
.then((response) => {
|
||||
const responseClone = response.clone();
|
||||
caches.open(DYNAMIC_CACHE).then((cache) => {
|
||||
cache.put(request, responseClone);
|
||||
});
|
||||
// Only cache successful responses
|
||||
if (response.ok) {
|
||||
const responseClone = response.clone();
|
||||
caches.open(DYNAMIC_CACHE).then((cache) => {
|
||||
cache.put(request, responseClone);
|
||||
});
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
Reference in New Issue
Block a user