src/service-worker/core.js
/**
 * Fetches the request, and stores it in the cache. Since we only store one
 * version of each file, we'll purge all older versions after we cache this.
 *
 * @param {!Cache} cache
 * @param {!Request} request
 * @param {!RtvVersion} requestVersion the version of the request
 * @param {string} requestPath the pathname of the request
 * @return {!Promise<!Response>}
 * @visibleForTesting
 */
Fetches the request, and stores it in the cache. Since we only store one
version of each file, we'll purge all older versions after we cache this.


Fetches the request and stores it in the cache . Since we only store one version of each file we ' ll purge all older versions after we cache this .
function fetchJsFile(cache, request, requestVersion, requestPath) {
  return fetchAndCache(cache, request).then(response => {
    diversions(cache).then(diversions => {
      purge(cache, requestVersion, requestPath, diversions);
      if (!diversions) {
        return;
      }
      let p = new Promise(resolve => {
        setTimeout(resolve, 10000);
      });
      for (let i = 0; i < diversions.length; i++) {
        p = p.then(() => {
          const diversionRequest = normalizedRequest(request, diversions[i]);
          return fetchAndCache(cache, diversionRequest);
        });
      }
    });
    return response;
  });
}
function fetchJsFile ( cache , request , requestVersion , requestPath ) { return fetchAndCache ( cache , request ) . then ( response => { diversions ( cache ) . then ( diversions => { purge ( cache , requestVersion , requestPath , diversions ) ; if ( ! diversions ) { return ; } let p = new Promise ( resolve => { setTimeout ( resolve , 10000 ) ; } ) ; for ( let i = 0 ; i < diversions . length ; i ++ ) { p = p . then ( ( ) => { const diversionRequest = normalizedRequest ( request , diversions [ i ] ) ; return fetchAndCache ( cache , diversionRequest ) ; } ) ; } } ) ; return response ; } ) ; }
Fetches the request, and stores it in the cache.
Fetches the request and stores it in the cache .
// TODO(jridgewell): we should also fetch this requestVersion for all files // we know about. // Fetch all diversions of this file. // This intentionally does not block the request resolution to speed // things up. // Prune old versions from the cache. // This also purges old diversions of other scripts, see `purge` for // detailed information. // Delay initial diversions requests by 10 seconds. // This is because diversions are low priority compared to page // content.