Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 1x 1x 14x 14x | /**
* Which runtime caching strategy an API GET gets (SB-908).
*
* Split out of `sw.js` so the patterns are testable: a service worker module
* cannot be imported in jsdom, and a regex that quietly stops matching is
* exactly the kind of bug that shows up as "the score is wrong on my phone".
*
* Two classes:
*
* - **Reference** — age groups, seasons, divisions, leagues, match types,
* teams, clubs. These change when an admin edits them and never on their
* own, so StaleWhileRevalidate is right: instant paint, refresh behind.
*
* - **Results** — standings and tournaments. Both carry match scores, and both
* change the moment a match ends. Serving those stale means the paint that
* matters is the wrong one: on 2026-08-29 a tournament page kept showing a
* pre-match state after the API had already returned the final score.
* NetworkFirst instead — the cache is a fallback for a slow or absent
* network, not the default answer.
*
* Not cached at all (no route here): auth, live match state, writes.
*/
const REFERENCE_PATH =
/\/api\/(teams|match-types|seasons|age-groups|divisions|leagues|clubs)(\/|\?|$)/;
const RESULTS_PATH = /\/api\/(standings|tournaments)(\/|\?|$)/;
/** Reference data: safe to serve from cache while it revalidates. */
export function isReferenceApi(pathAndSearch) {
return REFERENCE_PATH.test(pathAndSearch);
}
/** Score-bearing data: network first, cache only as a fallback. */
export function isResultsApi(pathAndSearch) {
return RESULTS_PATH.test(pathAndSearch);
}
|