From fb2508f6d8adcc3af9f458049317064eb80aae76 Mon Sep 17 00:00:00 2001 From: KANE LAZENI Date: Wed, 24 Dec 2025 09:24:15 +0000 Subject: [PATCH] a --- workbox-config.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 workbox-config.js diff --git a/workbox-config.js b/workbox-config.js new file mode 100644 index 0000000..de67656 --- /dev/null +++ b/workbox-config.js @@ -0,0 +1,63 @@ +module.exports = { + globDirectory: ".", + globPatterns: [ + "**/*.{css,js,png,jpg,jpeg,svg,gif,webp,woff,woff2,ttf,eot,ico,webmanifest}" + ], + globIgnores: [ + "node_modules/**", + "vendor/**", + "**/*.php", + "**/*.sql", + "**/*.log" + ], + swDest: "sw.js", + // Fallback hors ligne pour navigation + navigateFallback: "/offline.html", + // Exclure certaines routes de navigation si besoin (ex: admin très dynamique) + navigateFallbackDenylist: [ + /\/api\//, + /\/ajax\//, + /\/Cron\//, + /\/backoffice\// + ], + runtimeCaching: [ + // HTML navigation : NetworkFirst (toujours tenter le réseau, fallback cache) + { + urlPattern: ({ request }) => request.mode === "navigate", + handler: "NetworkFirst", + options: { + cacheName: "pages", + networkTimeoutSeconds: 5, + expiration: { maxEntries: 50, maxAgeSeconds: 7 * 24 * 60 * 60 } + } + }, + // JS/CSS : StaleWhileRevalidate + { + urlPattern: ({ request }) => + request.destination === "script" || request.destination === "style", + handler: "StaleWhileRevalidate", + options: { + cacheName: "assets", + expiration: { maxEntries: 200, maxAgeSeconds: 30 * 24 * 60 * 60 } + } + }, + // Images : CacheFirst + { + urlPattern: ({ request }) => request.destination === "image", + handler: "CacheFirst", + options: { + cacheName: "images", + expiration: { maxEntries: 200, maxAgeSeconds: 60 * 24 * 60 * 60 } + } + }, + // Fonts : CacheFirst + { + urlPattern: ({ request }) => request.destination === "font", + handler: "CacheFirst", + options: { + cacheName: "fonts", + expiration: { maxEntries: 50, maxAgeSeconds: 365 * 24 * 60 * 60 } + } + } + ] +};