From ca3be5d41bde1cad1edd02cb5b77cc14021c0f10 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Fri, 25 Oct 2024 16:53:47 +0300 Subject: [PATCH] $mol_offline refactor 3 - simplify respond --- offline/offline.web.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/offline/offline.web.ts b/offline/offline.web.ts index 81bfdab925..e0ce8c0ea9 100644 --- a/offline/offline.web.ts +++ b/offline/offline.web.ts @@ -151,13 +151,14 @@ namespace $ { async respond(event: FetchEvent) { const request = event.request - const cached = this.ignore_cache ? null : await caches.match( request ) + const cached = await caches.match( request ) if ( ! cached) return this.fetch_and_cache(event) if (request.cache === 'force-cache') return cached - if (request.cache === 'no-cache' || request.cache === 'reload') { + if (this.ignore_cache || request.cache === 'no-cache' || request.cache === 'reload') { + // fetch with fallback to cache if statuses not match try { const actual = await this.fetch_and_cache(event) if (actual.status === cached.status) return actual