Files
MealQuest/web/src/sw/apiStrategy.ts
T
dev_agent 81c5085f9a
CI / ci (push) Successful in 1m40s
Feature 06: PWA shell and offline (#58)
Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
2026-10-05 15:22:37 -04:00

17 lines
776 B
TypeScript

// 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] })
}