async _addURLToCache()

in workbox-v4.3.1/workbox-precaching.dev.js [410:465]


    async _addURLToCache({
      url,
      event,
      plugins
    }) {
      const request = new Request(url, {
        credentials: 'same-origin'
      });
      let response = await fetchWrapper_mjs.fetchWrapper.fetch({
        event,
        plugins,
        request
      }); // Allow developers to override the default logic about what is and isn't
      // valid by passing in a plugin implementing cacheWillUpdate(), e.g.
      // a workbox.cacheableResponse.Plugin instance.

      let cacheWillUpdateCallback;

      for (const plugin of plugins || []) {
        if ('cacheWillUpdate' in plugin) {
          cacheWillUpdateCallback = plugin.cacheWillUpdate.bind(plugin);
        }
      }

      const isValidResponse = cacheWillUpdateCallback ? // Use a callback if provided. It returns a truthy value if valid.
      cacheWillUpdateCallback({
        event,
        request,
        response
      }) : // Otherwise, default to considering any response status under 400 valid.
      // This includes, by default, considering opaque responses valid.
      response.status < 400; // Consider this a failure, leading to the `install` handler failing, if
      // we get back an invalid response.

      if (!isValidResponse) {
        throw new WorkboxError_mjs.WorkboxError('bad-precaching-response', {
          url,
          status: response.status
        });
      }

      if (response.redirected) {
        response = await cleanRedirect(response);
      }

      await cacheWrapper_mjs.cacheWrapper.put({
        event,
        plugins,
        request,
        response,
        cacheName: this._cacheName,
        matchOptions: {
          ignoreSearch: true
        }
      });
    }