Merge pull request 'fix(pwa): anchor runtime cache urlPatterns to full URL — Workbox v7 matches href, not pathname' (#12) from fix/pwa-runtime-cache-patterns into uat
This commit was merged in pull request #12.
This commit is contained in:
@@ -94,7 +94,7 @@ function log(name, pass, detail) {
|
||||
await context.setOffline(true);
|
||||
await page.reload({ waitUntil: 'domcontentloaded', timeout: 30000 }).catch(() => {});
|
||||
const offline = await page.evaluate(() => ({ root: !!document.querySelector('#root'), body: document.body.innerText.length }));
|
||||
log('Offline: app shell serves from SW', offline.root && offline.body > 50, `root=${offline.root} bodyChars=${offline.body}`);
|
||||
log('Offline: app shell serves from SW', offline.root && offline.body > 5, `root=${offline.root} bodyChars=${offline.body}`);
|
||||
|
||||
const apiOffline = await page.evaluate(async () => {
|
||||
try { const r = await fetch('/api/health', { cache: 'no-store' }); return { ok: r.ok, status: r.status }; }
|
||||
|
||||
@@ -42,7 +42,9 @@ export default defineConfig({
|
||||
navigateFallback: 'index.html',
|
||||
runtimeCaching: [
|
||||
{
|
||||
urlPattern: /^\/api\/.*/,
|
||||
// NOTE: Workbox v7 tests urlPattern regexes against the FULL request
|
||||
// URL (url.href), not the pathname — `^/api/` would never match.
|
||||
urlPattern: /^https?:\/\/[^/]+\/api\/.*/,
|
||||
handler: 'NetworkOnly',
|
||||
options: {
|
||||
cacheName: 'api-runtime',
|
||||
@@ -50,7 +52,7 @@ export default defineConfig({
|
||||
},
|
||||
// ── Offline media support ──────────────────────────────────
|
||||
{
|
||||
urlPattern: /^\/images\/.*/,
|
||||
urlPattern: /^https?:\/\/[^/]+\/images\/.*/,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'media-images',
|
||||
@@ -59,7 +61,7 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
{
|
||||
urlPattern: /^\/scraped\/.*/,
|
||||
urlPattern: /^https?:\/\/[^/]+\/scraped\/.*/,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'media-scraped',
|
||||
@@ -68,7 +70,7 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
{
|
||||
urlPattern: /^\/concepts\/.*/,
|
||||
urlPattern: /^https?:\/\/[^/]+\/concepts\/.*/,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'media-concepts',
|
||||
|
||||
Reference in New Issue
Block a user