lighthouse-core/audits/uses-rel-preload.js
/**
   * We want to preload all first party critical requests at depth 2.
   * Third party requests can be tricky to know the URL ahead of time.
   * Critical requests at depth 1 would already be identified by the browser for preloading.
   * Critical requests deeper than depth 2 are more likely to be a case-by-case basis such that it
   * would be a little risky to recommend blindly.
   *
   * @param {LH.Artifacts.NetworkRequest} request
   * @param {LH.Artifacts.NetworkRequest} mainResource
   * @param {Array<LH.Gatherer.Simulation.GraphNode>} initiatorPath
   * @return {boolean}
   */
We want to preload all first party critical requests at depth 2.
Third party requests can be tricky to know the URL ahead of time.
Critical requests at depth 1 would already be identified by the browser for preloading.
Critical requests deeper than depth 2 are more likely to be a case-by-case basis such that it
would be a little risky to recommend blindly.

@param {LH.Artifacts.NetworkRequest} request
@param {LH.Artifacts.NetworkRequest} mainResource
@param {Array} initiatorPath
@return {boolean}
We want to preload all first party critical requests at depth 2 . Third party requests can be tricky to know the URL ahead of time . Critical requests at depth 1 would already be identified by the browser for preloading . Critical requests deeper than depth 2 are more likely to be a case - by - case basis such that it would be a little risky to recommend blindly . @param { LH . Artifacts . NetworkRequest } request @param { LH . Artifacts . NetworkRequest } mainResource @param { Array } initiatorPath @return { boolean }
static shouldPreloadRequest(request, mainResource, initiatorPath) {
    const mainResourceDepth = mainResource.redirects ? mainResource.redirects.length : 0;
    if (request.isLinkPreload) return false;
    if (!CriticalRequestChains.isCritical(request, mainResource)) return false;
    if (URL.NON_NETWORK_PROTOCOLS.includes(request.protocol)) return false;
    if (initiatorPath.length !== mainResourceDepth + 2) return false;
    return URL.rootDomainsMatch(request.url, mainResource.url);
  }
static shouldPreloadRequest ( request , mainResource , initiatorPath ) { const mainResourceDepth = mainResource . redirects ? mainResource . redirects . length : 0 ; if ( request . isLinkPreload ) return false ; if ( ! CriticalRequestChains . isCritical ( request , mainResource ) ) return false ; if ( URL . NON_NETWORK_PROTOCOLS . includes ( request . protocol ) ) return false ; if ( initiatorPath . length !== mainResourceDepth + 2 ) return false ; return URL . rootDomainsMatch ( request . url , mainResource . url ) ; }
We want to preload all first party critical requests at depth 2.
We want to preload all first party critical requests at depth 2 .
// If it's already preloaded, no need to recommend it. // It's not critical, don't recommend it. // It's not a request loaded over the network, don't recommend it. // It's not at the right depth, don't recommend it. // We survived everything else, just check that it's a first party request.