diff --git a/cli/test/smokehouse/test-definitions/byte-efficiency.js b/cli/test/smokehouse/test-definitions/byte-efficiency.js index c25e34690c8e..01f057bbd551 100644 --- a/cli/test/smokehouse/test-definitions/byte-efficiency.js +++ b/cli/test/smokehouse/test-definitions/byte-efficiency.js @@ -187,25 +187,25 @@ const expectations = { items: [ { url: 'http://localhost:10200/byte-efficiency/script.js', - wastedBytes: '46039 +/- 100', + wastedBytes: '45816 +/- 100', wastedPercent: '87 +/- 5', }, { // /some-custom-url.js, url: 'inline: \n function unusedFunction() {\n // U…', - wastedBytes: '6690 +/- 100', + wastedBytes: '6630 +/- 100', wastedPercent: '99.6 +/- 0.1', }, { url: 'inline: \n // Used block #1\n // FILLER DATA JU…', - wastedBytes: '6569 +/- 100', + wastedBytes: '6510 +/- 100', wastedPercent: 100, }, { url: 'http://localhost:10200/byte-efficiency/bundle.js', totalBytes: '12962 +/- 1000', - wastedBytes: '2349 +/- 100', - wastedPercent: '19 +/- 5', + wastedBytes: '2303 +/- 100', + wastedPercent: '18 +/- 5', }, ], }, diff --git a/core/audits/byte-efficiency/unminified-javascript.js b/core/audits/byte-efficiency/unminified-javascript.js index 821bfc7845e1..c80bd6c20db1 100644 --- a/core/audits/byte-efficiency/unminified-javascript.js +++ b/core/audits/byte-efficiency/unminified-javascript.js @@ -7,7 +7,7 @@ import {ByteEfficiencyAudit} from './byte-efficiency-audit.js'; import * as i18n from '../../lib/i18n/i18n.js'; import {computeJSTokenLength as computeTokenLength} from '../../lib/minification-estimator.js'; -import {estimateTransferSize, getRequestForScript, isInline} from '../../lib/script-helpers.js'; +import {estimateCompressedContentSize, getRequestForScript, isInline} from '../../lib/script-helpers.js'; import {Util} from '../../../shared/util.js'; const UIStrings = { @@ -58,7 +58,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit { const contentLength = scriptContent.length; const totalTokenLength = computeTokenLength(scriptContent); - const totalBytes = estimateTransferSize(networkRecord, contentLength, 'Script'); + const totalBytes = estimateCompressedContentSize(networkRecord, contentLength, 'Script'); const wastedRatio = 1 - totalTokenLength / contentLength; const wastedBytes = Math.round(totalBytes * wastedRatio); diff --git a/core/test/audits/byte-efficiency/unminified-javascript-test.js b/core/test/audits/byte-efficiency/unminified-javascript-test.js index 11e0b3d4eb1d..2183b11bc069 100644 --- a/core/test/audits/byte-efficiency/unminified-javascript-test.js +++ b/core/test/audits/byte-efficiency/unminified-javascript-test.js @@ -14,6 +14,8 @@ const KB = 1024; const resourceType = 'Script'; describe('Page uses optimized responses', () => { it('fails when given unminified scripts', () => { + const responseHeaders = [{name: 'Content-Encoding'}]; + const commonRecord = {resourceType, responseHeaders}; const auditResult = UnminifiedJavascriptAudit.audit_({ URL: {finalDisplayedUrl: 'https://www.example.com'}, Scripts: [ @@ -59,10 +61,10 @@ describe('Page uses optimized responses', () => { }, ].map(createScript), }, [ - {requestId: '123.1', url: 'foo.js', transferSize: 20 * KB, resourceType}, - {requestId: '123.2', url: 'other.js', transferSize: 50 * KB, resourceType}, - {requestId: '123.3', url: 'valid-ish.js', transferSize: 100 * KB, resourceType}, - {requestId: '123.4', url: 'invalid.js', transferSize: 100 * KB, resourceType}, + {requestId: '123.1', url: 'foo.js', transferSize: 20 * KB, ...commonRecord}, + {requestId: '123.2', url: 'other.js', transferSize: 50 * KB, ...commonRecord}, + {requestId: '123.3', url: 'valid-ish.js', transferSize: 100 * KB, ...commonRecord}, + {requestId: '123.4', url: 'invalid.js', transferSize: 100 * KB, ...commonRecord}, ]); const results = auditResult.items.map(item => Object.assign(item, { diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 944eaabcd608..6094b082f427 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -4453,7 +4453,7 @@ "scoreDisplayMode": "metricSavings", "numericValue": 1200, "numericUnit": "millisecond", - "displayValue": "Potential savings of 82 KiB", + "displayValue": "Potential savings of 81 KiB", "warnings": [], "metricSavings": { "FCP": 0, @@ -4481,13 +4481,13 @@ "items": [ { "url": "http://localhost:10200/dobetterweb/third_party/aggressive-promise-polyfill.js", - "totalBytes": 166550, - "wastedBytes": 83568, + "totalBytes": 166320, + "wastedBytes": 83453, "wastedPercent": 50.176166426166425 } ], "overallSavingsMs": 1200, - "overallSavingsBytes": 83568, + "overallSavingsBytes": 83453, "sortedBy": [ "wastedBytes" ], @@ -10443,7 +10443,7 @@ "core/lib/i18n/i18n.js | displayValueByteSavings": [ { "values": { - "wastedBytes": 83568 + "wastedBytes": 83453 }, "path": "audits[unminified-javascript].displayValue" },