desire
This commit is contained in:
parent
54aff02658
commit
8bd4405fe8
33 changed files with 2478 additions and 610 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
const APP_VERSION = "15.24.2";
|
||||
const APP_VERSION = "15.24.14";
|
||||
const CACHE_NAME = `tarinai-colony-${APP_VERSION}`;
|
||||
const v = `v=${APP_VERSION}`;
|
||||
// Generated from app_manifest.json. Run scripts/generate_app_files.py after changing static files.
|
||||
|
|
@ -33,6 +33,15 @@ function isStaticAsset(request) {
|
|||
return /\.(?:js|css|webp|png|jpg|jpeg|gif|svg|mp3|wav|woff2?)$/i.test(url.pathname);
|
||||
}
|
||||
|
||||
function cacheableResponse(response) {
|
||||
return response && response.status === 200 && response.type !== "opaque";
|
||||
}
|
||||
|
||||
function putCacheSafely(request, response) {
|
||||
if (!cacheableResponse(response)) return Promise.resolve(false);
|
||||
return caches.open(CACHE_NAME).then(cache => cache.put(request, response.clone())).then(() => true).catch(() => false);
|
||||
}
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const request = event.request;
|
||||
if (request.method !== "GET") return;
|
||||
|
|
@ -41,16 +50,14 @@ self.addEventListener("fetch", (event) => {
|
|||
if (/service-worker\.js$/i.test(url.pathname)) return;
|
||||
if (request.mode === "navigate" || /index\.html$/i.test(url.pathname)) {
|
||||
event.respondWith(fetch(request).then(response => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => cache.put(request, copy));
|
||||
putCacheSafely(request, response);
|
||||
return response;
|
||||
}).catch(() => caches.match(request).then(cached => cached || caches.match("./index.html"))));
|
||||
return;
|
||||
}
|
||||
if (isStaticAsset(request)) {
|
||||
event.respondWith(caches.match(request).then(cached => cached || fetch(request).then(response => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => cache.put(request, copy));
|
||||
putCacheSafely(request, response);
|
||||
return response;
|
||||
})));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue