text: const FILES_TO_CACHE = [
      '/',
      '/index.html',
      '/styles.css',
      '/icons/icon-192x192.png',
      '/icons/icon-512x512.png',
      '/index.js',
      '/indexdb.js',
      '/manifest.webmanifest',
      'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
      'https://cdn.jsdelivr.net/npm/chart.js@2.8.0',
  ];
  
  const PRECACHE = 'precache-v1';
  const RUNTIME = 'runtime';
  
  // install
  self.addEventListener('install', function (event) {
    event.waitUntil(
      caches
        .open(PRECACHE)
        .then((cache) => cache.addAll(FILES_TO_CACHE))
        .then(self.skipWaiting())
    );
  });
  
  // activate 
  self.addEventListener("activate", function (event) {
    event.waitUntil(
      caches.keys().then(keyList => {
        return Promise.all(
          keyList.map(key => {
            if (key !==PRECACHE && key !== RUNTIME) {
            console.log("Removing old cache data", key);
            return caches.delete(key);
            }
          })
        );
      })
    );
  
    self.clients.claim();
  });
  
  // fetch
  self.addEventListener("fetch", function (event) {
    // cache successful requests to the API
    if (event.request.url.includes("/api/")) {
      event.respondWith(
        caches.open(RUNTIME).then(cache => {
          return fetch(event.request)
            .then(response => {
              // If the response was good, clone it and store it in the cache.
              if (response.status === 200) {
                cache.put(event.request.url, response.clone());
              }
              return response;
            })
            .catch(err => {
              // Network request failed, try to get it from the cache.
              return cache.match(event.request);
            });
        }).catch(err => console.log(err))
      );
    return;
    }
  
    // if the request is not for the API, serve static assets using "offline-first" approach.
    event.respondWith(
      caches.match(event.request).then(function (response) {
        return response || fetch(event.request);
      })
    );
  });