fix: cache canonical GTIN page without redirects
This commit is contained in:
@@ -10,14 +10,13 @@
|
||||
|
||||
const sw = /** @type {ServiceWorkerGlobalScope} */ (/** @type {unknown} */ (self));
|
||||
|
||||
const CACHE_VERSION = '15d23ab0263e';
|
||||
const CACHE_VERSION = '403b5842d1cd';
|
||||
const CACHE_PREFIX = 'desfoto-gtin-generator-';
|
||||
const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`;
|
||||
|
||||
// PRECACHE
|
||||
const PRECACHE = [
|
||||
'./',
|
||||
'./index.html',
|
||||
'./css/app.css',
|
||||
'./js/app.js',
|
||||
'./js/gtin.js',
|
||||
@@ -36,7 +35,7 @@ function scopeUrl(pfad) {
|
||||
return new URL(pfad, sw.registration.scope).toString();
|
||||
}
|
||||
|
||||
const INDEX_URL = scopeUrl('./index.html');
|
||||
const INDEX_URL = scopeUrl('./');
|
||||
|
||||
/** Pfad des Geltungsbereichs, z. B. "/gtin/". */
|
||||
const SCOPE_PFAD = new URL(sw.registration.scope).pathname;
|
||||
@@ -59,7 +58,7 @@ const SHELL_KENNUNG = 'id="artikelnummer"';
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function istAnwendungshuelle(antwort) {
|
||||
if (!antwort.ok || antwort.type !== 'basic') return false;
|
||||
if (!antwort.ok || antwort.type !== 'basic' || antwort.redirected) return false;
|
||||
const inhaltstyp = antwort.headers.get('content-type') ?? '';
|
||||
if (!inhaltstyp.includes('text/html')) return false;
|
||||
const endgueltig = new URL(antwort.url);
|
||||
@@ -147,8 +146,7 @@ sw.addEventListener('fetch', (ereignis) => {
|
||||
|
||||
if (anfrage.mode === 'navigate') {
|
||||
const appStart = new URL('./', sw.registration.scope).pathname;
|
||||
const appIndex = new URL('./index.html', sw.registration.scope).pathname;
|
||||
if (ziel.pathname !== appStart && ziel.pathname !== appIndex) return;
|
||||
if (ziel.pathname !== appStart) return;
|
||||
ereignis.respondWith(bedieneNavigation(ereignis, anfrage));
|
||||
return;
|
||||
}
|
||||
@@ -157,7 +155,7 @@ sw.addEventListener('fetch', (ereignis) => {
|
||||
caches.match(anfrage).then((treffer) => {
|
||||
if (treffer) return treffer;
|
||||
return fetch(anfrage).then((antwort) => {
|
||||
if (antwort.ok && antwort.type === 'basic') {
|
||||
if (antwort.ok && antwort.type === 'basic' && !antwort.redirected) {
|
||||
const kopie = antwort.clone();
|
||||
ereignis.waitUntil(
|
||||
caches
|
||||
|
||||
Reference in New Issue
Block a user