diff options
author | Alex Shpak <alex-shpak@users.noreply.github.com> | 2020-04-21 22:35:30 +0200 |
---|---|---|
committer | Alex Shpak <alex-shpak@users.noreply.github.com> | 2020-05-01 13:19:58 +0200 |
commit | c672d64f126178f0facb91204761b1b913743d71 (patch) | |
tree | d2de47eeb45c0bb4d76cf7de2c1635f2a7cb07df /static/sw.js | |
parent | 9c5fc12dd8fba31d6b5ced553d9748ec87dd9474 (diff) |
Generate pages list in sw.js
Diffstat (limited to 'static/sw.js')
-rw-r--r-- | static/sw.js | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/static/sw.js b/static/sw.js deleted file mode 100644 index d42b04c..0000000 --- a/static/sw.js +++ /dev/null @@ -1,44 +0,0 @@ -self.addEventListener("install", function (event) { - self.skipWaiting(); -}); - -self.addEventListener("fetch", (event) => { - const cacheName = self.location.pathname - const request = event.request; - - if (request.method !== "GET") { - return; - } - - /** - * @param {Response} response - * @returns {Promise<Response>} - */ - function saveToCache(response) { - if (cacheable(response)) { - return caches - .open(cacheName) - .then((cache) => cache.put(request, response.clone())) - .then(() => response); - } else { - return response; - } - } - - /** - * @param {Error} error - */ - function serveFromCache(error) { - return caches.open(cacheName).then((cache) => cache.match(request.url)); - } - - /** - * @param {Response} response - * @returns {Boolean} - */ - function cacheable(response) { - return response.type === "basic" && response.ok && !response.headers.has("Content-Disposition") - } - - event.respondWith(fetch(request).then(saveToCache).catch(serveFromCache)); -}); |