Verified Commit 070de5ad authored by Mehdi Baaboura's avatar Mehdi Baaboura
Browse files

Removed service worker cache

parent e47564eb
......@@ -18,76 +18,7 @@
*/
const CACHE_NAME = "qpost-sw-precache";
const PRECACHE_FILES = [];
const LOG_PREFIX = "[QPOST-SW] ";
const OFFLINE_PAGE = "/offline.html";
self.addEventListener("install", (event) => {
console.log(LOG_PREFIX + "Installing");
console.log(LOG_PREFIX + "Skip waiting on install");
self.skipWaiting();
// Add assets to cache
event.waitUntil(caches.open(CACHE_NAME).then(cache => {
console.log(LOG_PREFIX + "Caching pages during install");
return cache.addAll(PRECACHE_FILES);
}));
});
self.addEventListener("activate", (event) => {
console.log(LOG_PREFIX + "Claiming clients for current page");
event.waitUntil(self.clients.claim());
});
self.addEventListener("fetch", (event) => {
// Serve from cache if a fetch fails
const request = event.request;
// only cache HTTP GET requests
if (request.method !== "GET") return;
event.respondWith(fetch(request).then(response => {
event.waitUntil(updateCache(request, response.clone()));
return response;
}).catch(error => {
if (request.destination !== "document" || request.mode !== "navigate") return;
console.error(LOG_PREFIX + "Network request failed. Serving offline page", error);
return caches.open(CACHE_NAME).then(cache => {
return cache.match(OFFLINE_PAGE)
});
}));
});
self.addEventListener("refreshOffline", () => {
const offlinePageRequest = new Request(OFFLINE_PAGE);
return fetch(OFFLINE_PAGE).then((response) => {
return updateCache(offlinePageRequest, response);
});
});
loadFromCache = request => {
return caches.open(CACHE_NAME).then(cache => {
return cache.match(request).then(matching => {
if (!matching || matching.status === 404) {
return Promise.reject("No match was found.");
}
return matching;
});
});
};
updateCache = (request, response) => {
return caches.open(CACHE_NAME).then(cache => {
return cache.put(request, response);
});
};
// https://github.com/bpolaszek/webpush-js/blob/master/src/webpush-sw.js
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment