0
I have develop blazor WASM application for offline thats why I had implement the service worker to intercept the request then serve the resource to the client using cache. Service worker successfully on chrome and edge but in firebox once application load at the time service worker serve the resource to the client then with in 5-10 secs service worker stopped sunddenly and show the start button I had observe this on application tab with service worker on browser. It shows service stopped suddenly. If I had tried to run application offline i got this message on firefox browser that is
Offline mode
Firefox is currently in offline mode and can’t browse the Web.
Press “Try Again” to switch to online mode and reload the page.
If manually click start service worker then run offline not working.
service-worker.published.js
const cacheName = 'blazor-cache-v1';
const assetsToCache = [
'/',
'/index.html',
'/css/bootstrap/bootstrap.min.css',
'/css/bootstrap-5.3.3-dist/css/bootstrap.min.css',
'/fontawesome-free-5.15.4-web/css/all.css',
'/style.css',
'/_content/Blazored.Typeahead/blazored-typeahead.css',
'/apple-touch-icon.png',
'/favicon-32x32.png',
'/favicon-16x16.png',
'/sample-data/manifest.json',
'/safari-pinned-tab.svg',
'/css/app.css',
'/css/signin.css',
'/css/Locations.css',
'/_content/Blazored.Toast/blazored-toast.min.css',
'/_framework/blazor.webassembly.js',
'/_content/BlazorIndexedDB/dexie.min.js',
'/_content/BlazorIndexedDB/blazorDB.js',
'/_content/Blazored.Typeahead/blazored-typeahead.js',
'/css/bootstrap-5.3.3-dist/js/bootstrap.bundle.js',
'/jquery-3.6.0.min.js',
'/css/bootstrap-5.3.3-dist/js/bootstrap.min.js',
'/js/bs5-toast.min.js',
'/js/Syncloading.js',
'/scripts.js',
'/js/site.js',
'/js/globalErrorHandler.js'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName).then(cache => {
return cache.addAll(assetsToCache);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request).then(networkResponse => {
if (event.request.method === 'GET' && networkResponse.type === 'basic') {
return caches.open(cacheName).then(cache => {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
} else {
return networkResponse;
}
});
})
);
});
self.addEventListener('activate', event => {
const currentCaches = [cacheName];
event.waitUntil(
caches.keys().then(cacheNames => {
return cacheNames.filter(cacheName => !currentCaches.includes(cacheName));
}).then(cachesToDelete => {
return Promise.all(cachesToDelete.map(cacheToDelete => {
return caches.delete(cacheToDelete);
}));
}).then(() => self.clients.claim())
);
});
What I have tried:
Firefox is currently in offline mode and can’t browse the Web.
Press “Try Again” to switch to online mode and reload the page.
If manually click start service worker then run offline not working.