Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #58.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// The network-first strategy for API reads, kept apart from src/sw.ts so the
|
||||
// tests can run it without a service worker.
|
||||
import type { WorkboxPlugin } from 'workbox-core/types'
|
||||
import { NetworkFirst } from 'workbox-strategies'
|
||||
import { cacheNames, markCacheFallback, networkTimeoutSeconds } from './routes'
|
||||
|
||||
// NetworkFirst reads its cache only when the network fails or times out, so
|
||||
// every cached response it uses is a fallback.
|
||||
const markFallback: WorkboxPlugin = {
|
||||
cachedResponseWillBeUsed: async ({ cachedResponse }) =>
|
||||
cachedResponse === undefined ? undefined : markCacheFallback(cachedResponse),
|
||||
}
|
||||
|
||||
export function createApiStrategy(): NetworkFirst {
|
||||
return new NetworkFirst({ cacheName: cacheNames.api, networkTimeoutSeconds, plugins: [markFallback] })
|
||||
}
|
||||
Reference in New Issue
Block a user