<commit_before>if (__DEV__) {
  console.log('Service Worker initialized.');
}

self.addEventListener('install', event => {
  if (__DEV__) {
    console.log('Service Worker installed.');
  }
});

self.addEventListener('activate', event => {
  if (__DEV__) {
    console.log('Service Worker activated.');
    // Force refresh service worker
    event.waitUntil(global.clients.claim());
  }
});

self.addEventListener('onmessage', message => {
  if (__DEV__) {
    console.log('Message received', message);
  }
});<commit_msg>Cache index in service worker<commit_after>const CACHE = '0.10';
const INDEX_CACHE_URL = '/';
const INDEX_ROUTES = ['/', '/logbook', '/history', '/map', '/devService', '/devState',
                      '/devEvent', '/devInfo', '/states'];

if (__DEV__) {
  console.log('Service Worker initialized.');
}

self.addEventListener('install', event => {
  if (__DEV__) {
    console.log('Service Worker installed.');
  }

  event.waitUntil(
    caches.open(CACHE).then(cache => cache.add(INDEX_CACHE_URL))
  );
});

self.addEventListener('activate', event => {
  if (__DEV__) {
    console.log('Service Worker activated.');
    // Force refresh service worker
    event.waitUntil(global.clients.claim());
  }
});

self.addEventListener('message', event => {
  if (__DEV__) {
    console.log('Message received', event.data);
  }
});

self.addEventListener('fetch', event => {
  const path = event.request.url.substr(event.request.url.indexOf('/', 7));

  if (event.request.mode !== 'same-origin' || !INDEX_ROUTES.includes(path)) {
    return fetch(event.request);
  }

  event.respondWith(
    caches.open(CACHE).then(cache => {
      return cache.match(INDEX_CACHE_URL).then(cachedResponse => {
        const networkFetch = fetch(event.request).then(response => {
          cache.put(INDEX_CACHE_URL, response.clone());
          return response;
        });

        if (__DEV__ && cachedResponse) {
          console.log('Serving cached response for', path);
        }

        return cachedResponse || networkFetch;
      });
    })
  );
});
{'fraction_non_alphanumeric': 0.1726479146459748, 'fraction_numerical': 0.0019398642095053346, 'mean_word_length': 3.417558886509636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3073493', 'n_tokens_mistral': 616, 'n_tokens_neox': 613, 'n_words': 118}