text: const FILES_TO_CACHE = [
    "/",
    "/index.html",
    "/favorites.html",
    "/assets/css/style.css",
    "https://fonts.googleapis.com/css?family=Istok+Web|Montserrat:800&display=swap",
    "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
  ];
  
  const PRECACHE = "precache-v1";
  const RUNTIME = "runtime";
  
  window.self.addEventListener("install", (event) => {
    event.waitUntil(
      caches
        .open(PRECACHE)
        .then((cache) => cache.addAll(FILES_TO_CACHE))
        .then(window.self.skipWaiting())
    );
  });
  
  // The activate handler takes care of cleaning up old caches.
  window.self.addEventListener("activate", (event) => {
    const currentCaches = [PRECACHE, RUNTIME];
    event.waitUntil(
      caches
        .keys()
        .then((cacheNames) => {
          return cacheNames.filter(
            (cacheName) => !currentCaches.includes(cacheName)
          );
        })
        .then((cachesToDelete) => {
          return Promise.all(
            cachesToDelete.map((cacheToDelete) => {
              return caches.delete(cacheToDelete);
            })
          );
        })
        .then(() => window.self.clients.claim())
    );
  });
  
  window.self.addEventListener("fetch", (event) => {
    if (event.request.url.startsWith(window.self.location.origin)) {
      event.respondWith(
        caches.match(event.request).then((cachedResponse) => {
          if (cachedResponse) {
            return cachedResponse;
          }
  
          return caches.open(RUNTIME).then((cache) => {
            return fetch(event.request).then((response) => {
              return cache.put(event.request, response.clone()).then(() => {
                return response;
              });
            });
          });
        })
      );
    }
  });
  