@ -28,11 +28,10 @@ self.addEventListener('fetch', function(event) {
const asyncResponse = fetchRoot ( ) ;
const asyncResponse = fetchRoot ( ) ;
const asyncCache = openWebCache ( ) ;
const asyncCache = openWebCache ( ) ;
event . respondWith ( asyncResponse . then ( async response => {
event . respondWith ( asyncResponse . then ( response => {
if ( response . ok ) {
if ( response . ok ) {
const cache = await asyncCache ;
return asyncCache . then ( cache => cache . put ( '/' , response ) )
await cache . put ( '/' , response ) ;
. then ( ( ) => response . clone ( ) ) ;
return response . clone ( ) ;
}
}
throw null ;
throw null ;
@ -41,35 +40,38 @@ self.addEventListener('fetch', function(event) {
const asyncResponse = fetch ( event . request ) ;
const asyncResponse = fetch ( event . request ) ;
const asyncCache = openWebCache ( ) ;
const asyncCache = openWebCache ( ) ;
event . respondWith ( asyncResponse . then ( async response => {
event . respondWith ( asyncResponse . then ( response => {
if ( response . ok || response . type === 'opaqueredirect' ) {
if ( response . ok || response . type === 'opaqueredirect' ) {
await Promise . all ( [
return Promise . all ( [
asyncCache . then ( cache => cache . delete ( '/' ) ) ,
asyncCache . then ( cache => cache . delete ( '/' ) ) ,
indexedDB . deleteDatabase ( 'mastodon' ) ,
indexedDB . deleteDatabase ( 'mastodon' ) ,
] ) ;
] ) .then ( ( ) => response ) ;
}
}
return response ;
return response ;
} ) ) ;
} ) ) ;
} else if ( process . env . CDN _HOST ? url . host === process . env . CDN _HOST : url . pathname . startsWith ( '/system/' ) ) {
} else if ( process . env . CDN _HOST ? url . host === process . env . CDN _HOST : url . pathname . startsWith ( '/system/' ) ) {
event . respondWith ( openSystemCache ( ) . then ( async cache => {
event . respondWith ( openSystemCache ( ) . then ( cache => {
const cached = await cache . match ( event . request . url ) ;
return cache . match ( event . request . url ) . then ( cached => {
if ( cached === undefined ) {
return fetch ( event . request ) . then ( fetched => {
if ( fetched . ok ) {
const put = cache . put ( event . request . url , fetched . clone ( ) ) ;
if ( cached === undefined ) {
put . catch ( ( ) => freeStorage ( ) ) ;
const fetched = await fetch ( event . request ) ;
if ( fetched . ok ) {
return put . then ( ( ) => {
try {
freeStorage ( ) ;
await cache . put ( event . request . url , fetched . clone ( ) ) ;
return fetched ;
} finally {
} ) ;
freeStorage ( ) ;
}
}
}
return fetched ;
return fetched ;
}
} ) ;
}
return cached ;
return cached ;
} ) ;
} ) ) ;
} ) ) ;
}
}
} ) ;
} ) ;