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