mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 11:48:26 -04:00
Add some debugging to PWA SW
Former-commit-id: ac7b9d36b1756b0f4827df2b4a58ac1a727e7011 [formerly fdeffde031bf788504670eec3f2208c739ada657] Former-commit-id: 06d05bc4cfafc392cb77fc5ce406e5e3f123f15f
This commit is contained in:
parent
d052444986
commit
b55fe28647
@ -15,17 +15,17 @@
|
||||
"generated": "true",
|
||||
"icons": [
|
||||
{
|
||||
"src": "img/icons/kiwix-48.png",
|
||||
"sizes": "48x48",
|
||||
"src": "www/img/icons/kiwix-48.png",
|
||||
"sizes": "48x48 96x96",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "img/icons/kiwix-64.ico",
|
||||
"sizes": "64x64 96x96 128x128",
|
||||
"src": "www/img/icons/kiwix-64.ico",
|
||||
"sizes": "64x64 128x128",
|
||||
"type": "image/ico"
|
||||
},
|
||||
{
|
||||
"src": "img/icons/kiwix-256.png",
|
||||
"src": "www/img/icons/kiwix-256.png",
|
||||
"sizes": "256x256 512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
// This is the service worker with the Cache-first network
|
||||
// Service Worker with Cache-first network, with some code from pwabuilder.com
|
||||
|
||||
const CACHE = "pwabuilder-precache";
|
||||
const CACHE = "sw-precache";
|
||||
const precacheFiles = [
|
||||
"www/index.html",
|
||||
"www/js/init.js",
|
||||
"www/js/app.js"
|
||||
"www/js/app.js",
|
||||
"www/js/lib/jquery-3.2.1.slim.js",
|
||||
"www/js/lib/require.js",
|
||||
"www/js/lib/bootstrap.js",
|
||||
"www/js/lib/q.js",
|
||||
"www/js/lib/xzdec.js"
|
||||
];
|
||||
|
||||
self.addEventListener("install", function (event) {
|
||||
console.log("[PWA Builder] Install Event processing");
|
||||
console.log("[SW] Install Event processing");
|
||||
|
||||
console.log("[PWA Builder] Skip waiting on install");
|
||||
console.log("[SW] Skip waiting on install");
|
||||
self.skipWaiting();
|
||||
|
||||
event.waitUntil(
|
||||
caches.open(CACHE).then(function (cache) {
|
||||
console.log("[PWA Builder] Caching pages during install");
|
||||
console.log("[SW] Caching pages during install");
|
||||
return cache.addAll(precacheFiles);
|
||||
})
|
||||
);
|
||||
@ -23,14 +28,14 @@ self.addEventListener("install", function (event) {
|
||||
|
||||
// Allow sw to control of current page
|
||||
self.addEventListener("activate", function (event) {
|
||||
console.log("[PWA Builder] Claiming clients for current page");
|
||||
console.log("[SW] Claiming clients for current page");
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
||||
// If any fetch fails, it will look for the request in the cache and serve it from there first
|
||||
self.addEventListener("fetch", function (event) {
|
||||
console.log('[SW] Service Worker ' + (event.request.method === "GET" ? 'noted ' : 'intercepted ') + event.request.url, event.request.method);
|
||||
if (event.request.method !== "GET") return;
|
||||
console.log('Service Worker intercepted: ' + event.request.url);
|
||||
event.respondWith(
|
||||
fromCache(event.request).then(
|
||||
function (response) {
|
||||
@ -40,10 +45,11 @@ self.addEventListener("fetch", function (event) {
|
||||
// file to use the next time we show view
|
||||
event.waitUntil(
|
||||
fetch(event.request).then(function (response) {
|
||||
console.log('[SW] Refreshing CACHE from server...');
|
||||
return updateCache(event.request, response);
|
||||
})
|
||||
);
|
||||
|
||||
console.log('[SW] Supplying ' + event.request.url + ' from CACHE...');
|
||||
return response;
|
||||
},
|
||||
function () {
|
||||
@ -56,7 +62,7 @@ self.addEventListener("fetch", function (event) {
|
||||
return response;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log("[PWA Builder] Network request failed and no cache." + error);
|
||||
console.log("[PWA Builder] Network request failed and no cache.", error);
|
||||
});
|
||||
}
|
||||
)
|
||||
|
@ -70,7 +70,7 @@
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('Sorry, looks like Service Worker is not available today...');
|
||||
console.log('Service Worker is not available on this platform...');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
Loading…
x
Reference in New Issue
Block a user