importScripts("workbox/workbox-sw.js");
self.addEventListener("install", (e) => {
  self.skipWaiting();
});

if (workbox) {
  workbox.core.setCacheNameDetails({
    prefix: "home-app",
    suffix: "0.0.5",
    precache: "precache",
    runtime: "runtime",
  });
  workbox.routing.registerRoute(
    /\/assets/,
    new workbox.strategies.CacheFirst({
      plugins: [
        new workbox.expiration.Plugin({
          maxAgeSeconds: 24 * 60 * 60,
        }),
      ],
      cacheName: "assets",
    })
  );
  workbox.routing.registerRoute(
    "/manifest.json",
    new workbox.strategies.StaleWhileRevalidate({
      plugins: [
        new workbox.expiration.Plugin({
          maxAgeSeconds: 7 * 24 * 60 * 60,
        }),
      ],
      cacheName: "assets",
    })
  );
  workbox.routing.registerRoute(
    "/",
    new workbox.strategies.StaleWhileRevalidate({
      plugins: [
        new workbox.expiration.Plugin({
          maxAgeSeconds: 60 * 60 * 24,
        }),
      ],
      cacheName: "assets",
    })
  );
  workbox.routing.registerRoute(
    /\**/,
    new workbox.strategies.StaleWhileRevalidate({
      plugins: [
        new workbox.expiration.Plugin({
          maxAgeSeconds: 60 * 60 * 24,
        }),
      ],
      cacheName: "assets",
    })
  );
}
