code: function onInstall(event) {
    const preCacheApplication = async () => {
      const cache = await caches.open(CACHE_NAME);
      // Fetching these with addAll fails for CORS-restricted content, so we use
      // fetchAndCache with no-cors mode to work around it.
  
      // Optional resources: failure on these will NOT fail the Promise chain.
      // We will also not wait for them to be installed.
      for (const url of OPTIONAL_RESOURCES) {
        const request = new Request(url, {mode: 'no-cors'});
        fetchAndCache(cache, request).catch(() => {});
      }
  
      // Critical resources: failure on these will fail the Promise chain.
      // The installation will not be complete until these are all cached.
      const criticalFetches = [];
      for (const url of CRITICAL_RESOURCES) {
        const request = new Request(url, {mode: 'no-cors'});
        criticalFetches.push(fetchAndCache(cache, request));
      }
      return Promise.all(criticalFetches);
    };
  
    event.waitUntil(preCacheApplication());
  }
docs: This event fires when the service worker is installed.
  
  @param {!InstallEvent} event