feat: use StaleWhileRevalidate for scripts poloicy; v1.104.2

This commit is contained in:
Azgaar 2024-09-20 13:04:47 +02:00
parent d3ba6dd95b
commit 3d1f268003
5 changed files with 33 additions and 40 deletions

9
sw.js
View file

@ -1,7 +1,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
const {Route, registerRoute} = workbox.routing;
const {CacheFirst, NetworkFirst} = workbox.strategies;
const {CacheFirst, NetworkFirst, StaleWhileRevalidate} = workbox.strategies;
const {CacheableResponsePlugin} = workbox.cacheableResponse;
const {ExpirationPlugin} = workbox.expiration;
@ -18,8 +18,11 @@ registerRoute(
registerRoute(
({request, url}) =>
request.destination === "script" && !url.pathname.endsWith("min.js") && !url.pathname.includes("versioning.js"),
new CacheFirst({
request.destination === "script" &&
!url.pathname.endsWith("min.js") &&
!url.pathname.includes("versioning.js") &&
!url.contains("google"),
new StaleWhileRevalidate({
cacheName: "fmg-scripts",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),