Skip to content

Commit

Permalink
$mol_offline refactor 3 - simplify respond
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 25, 2024
1 parent ce606ba commit ca3be5d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions offline/offline.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca3be5d

Please sign in to comment.