function estimateCompressionRatioForContent(compressionRatioByUrl, url,
  artifacts, networkRecords) {
  let compressionRatio = compressionRatioByUrl.get(url);
  if (compressionRatio !== undefined) return compressionRatio;

  const script = artifacts.Scripts.find(script => script.url === url);

  if (!script) {
    // Can't find content, so just use 1.
    compressionRatio = 1;
  } else {
    const networkRecord = getRequestForScript(networkRecords, script);
    const contentLength = networkRecord?.resourceSize || script.length || 0;
    const compressedSize = estimateCompressedContentSize(networkRecord, contentLength, 'Script');
    compressionRatio = compressedSize / contentLength;
  }

  compressionRatioByUrl.set(url, compressionRatio);
  return compressionRatio;
}
Utility function to estimate the ratio of the compression on the resource.
This excludes the size of the response headers.
Also caches the calculation.
@param {Map<string, number>} compressionRatioByUrl
@param {string} url
@param {LH.Artifacts} artifacts
@param {Array<LH.Artifacts.NetworkRequest>} networkRecords