@ -124,17 +124,23 @@ const cacheFirst = async ({ request, preloadResponsePromise, refreshAnyway }) =>
}
// Next try to use (and cache) the preloaded response, if it's there
if ( preloadResponsePromise ) {
const preloadResponse = await preloadResponsePromise
if ( preloadResponse && preloadResponse . ok ) {
console . info ( '[cf] using preload response' , preloadResponse )
await putInCache ( request , preloadResponse . clone ( ) )
return preloadResponse
}
else {
console . log ( '[cf] got not ok preloadResponse, ignoring' , preloadResponse )
try {
if ( preloadResponsePromise ) {
const preloadResponse = await preloadResponsePromise
if ( preloadResponse && preloadResponse . ok ) {
console . info ( '[cf] using preload response' , preloadResponse )
await putInCache ( request , preloadResponse . clone ( ) )
return preloadResponse
}
else {
console . log ( '[cf] got not ok preloadResponse, ignoring' , preloadResponse )
}
}
}
catch ( e ) {
// Ignore as preload isn't necessarily important
console . error ( '[cf] preload response error' , e )
}
// Next try to get the resource from the network
const responseFromNetwork = await fetch ( request )
@ -153,17 +159,23 @@ const cacheFirst = async ({ request, preloadResponsePromise, refreshAnyway }) =>
const networkFirst = async ( { request , preloadResponsePromise } ) => {
// First try to use (and cache) the preloaded response, if it's there
if ( preloadResponsePromise ) {
const preloadResponse = await preloadResponsePromise
if ( preloadResponse && preloadResponse . ok ) {
console . info ( '[nf] using preload response' , preloadResponse )
await putInCache ( request , preloadResponse . clone ( ) )
return preloadResponse
}
else {
console . log ( '[nf] got not ok preloadResponse, ignoring' , preloadResponse )
try {
if ( preloadResponsePromise ) {
const preloadResponse = await preloadResponsePromise
if ( preloadResponse && preloadResponse . ok ) {
console . info ( '[nf] using preload response' , preloadResponse )
await putInCache ( request , preloadResponse . clone ( ) )
return preloadResponse
}
else {
console . log ( '[nf] got not ok preloadResponse, ignoring' , preloadResponse )
}
}
}
catch ( e ) {
// Ignore as preload isn't necessarily important
console . error ( '[nf] preload response error' , e )
}
// Next try to get the resource from the network
let responseFromNetwork