<commit_before>/* globals self, caches, fetch */

const activeCacheName = "v7";

// eslint-disable-next-line no-restricted-globals
self.addEventListener("install", (event) => {
  event.waitUntil(
    caches.open(activeCacheName).then((cache) => {
      return cache.addAll([
        "/img/logo.blue.transparent.192.png",
        "/img/logo.blue.white.192.png",
        "/img/logo.wh.svg",
        "/img/musikkforeningen-nidarholm.jpg",
      ]);
    }),
  );
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("fetch", (event) => {
  event.respondWith(
    new Promise((fulfill, reject) => {
      const timeoutId = setTimeout(reject, 400);
      fetch(event.request).then((response) => {
        clearTimeout(timeoutId);
        fulfill(response);
      }, reject);
    }).catch(() => {
      return caches.open(activeCacheName).then((cache) => {
        return cache.match(event.request).then((result) => {
          // cache.put(event.request, response.clone());
          return result || Promise.reject(new Error("no-match"));
        });
      });
    }),
  );
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("activate", (event) => {
  const cacheKeeplist = [activeCacheName];

  event.waitUntil(
    caches.keys().then((keyList) => {
      return Promise.all(
        keyList.map((key) => {
          if (cacheKeeplist.indexOf(key) === -1) {
            return caches.delete(key);
          }
          return caches[key];
        }),
      );
    }),
  );
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("activate", (event) => {
  // eslint-disable-next-line no-restricted-globals
  event.waitUntil(self.clients.claim());
});<commit_msg>Trying service worker again, using mozilla cookbook.<commit_after>/* globals self, caches, fetch */

const activeCacheName = "v8";

/**
 * Cache static elements
 */
function precache() {
  return caches.open(activeCacheName).then((cache) => {
    return cache.addAll([
      "/img/logo.blue.transparent.192.png",
      "/img/logo.blue.white.192.png",
      "/img/logo.wh.svg",
      "/img/musikkforeningen-nidarholm.jpg",
    ]);
  });
}

/**
 * Return data from cache
 */
function fromCache(request) {
  return caches.open(activeCacheName).then((cache) => {
    return cache.match(request).then((response) => {
      // cache.put(event.request, response.clone());
      return response || Promise.reject(new Error("no-match"));
    });
  });
}

function update(request) {
  return caches.open(activeCacheName).then((cache) => {
    return fetch(request).then((response) => {
      return cache.put(request, response);
    });
  });
}

// eslint-disable-next-line no-restricted-globals
self.addEventListener("install", (event) => {
  event.waitUntil(precache());
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("fetch", (event) => {
  event.respondWith(fromCache(event.request));
  event.waitUntil(update(event.request));
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("activate", (event) => {
  const cacheKeeplist = [activeCacheName];

  event.waitUntil(
    caches.keys().then((keyList) => {
      return Promise.all(
        keyList.map((key) => {
          if (cacheKeeplist.indexOf(key) === -1) {
            return caches.delete(key);
          }
          return caches[key];
        }),
      );
    }),
  );
});

// eslint-disable-next-line no-restricted-globals
self.addEventListener("activate", (event) => {
  // eslint-disable-next-line no-restricted-globals
  event.waitUntil(self.clients.claim());
});
{'fraction_non_alphanumeric': 0.18007769145394006, 'fraction_numerical': 0.005271920088790233, 'mean_word_length': 3.0011098779134295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '279886', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1130, 'n_words': 162}