diff --git a/core/audits/byte-efficiency/uses-text-compression.js b/core/audits/byte-efficiency/uses-text-compression.js index 6821453d6e54..65b716da2af2 100644 --- a/core/audits/byte-efficiency/uses-text-compression.js +++ b/core/audits/byte-efficiency/uses-text-compression.js @@ -25,7 +25,6 @@ const UIStrings = { const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings); const IGNORE_THRESHOLD_IN_BYTES = 1400; -const IGNORE_THRESHOLD_IN_PERCENT = 0.1; class ResponsesAreCompressed extends ByteEfficiencyAudit { /** @@ -59,12 +58,8 @@ class ResponsesAreCompressed extends ByteEfficiencyAudit { const gzipSize = record.gzipSize; const gzipSavings = originalSize - gzipSize; - // we require at least 10% savings off the original size AND at least 1400 bytes - // if the savings is smaller than either, we don't care - if (1 - gzipSize / originalSize < IGNORE_THRESHOLD_IN_PERCENT || - gzipSavings < IGNORE_THRESHOLD_IN_BYTES || - record.transferSize < gzipSize - ) { + // We require at minimum amount of savings. + if (gzipSavings < IGNORE_THRESHOLD_IN_BYTES || record.transferSize < gzipSize) { return; } diff --git a/core/test/audits/byte-efficiency/uses-text-compression-test.js b/core/test/audits/byte-efficiency/uses-text-compression-test.js index 3fffa1b32336..1da5240380ab 100644 --- a/core/test/audits/byte-efficiency/uses-text-compression-test.js +++ b/core/test/audits/byte-efficiency/uses-text-compression-test.js @@ -4,44 +4,33 @@ * SPDX-License-Identifier: Apache-2.0 */ -const KB = 1024; -import assert from 'assert/strict'; - import ResponsesAreCompressedAudit from '../../../audits/byte-efficiency/uses-text-compression.js'; +const KB = 1024; + function generateResponse(options) { - return Object.assign({ + return { url: `http://google.com/${options.file}`, transferSize: options.resourceSize || 0, resourceSize: 0, gzipSize: 0, - }, options); + ...options, + }; } describe('Page uses optimized responses', () => { - it('fails when responses are collectively unoptimized', () => { - const auditResult = ResponsesAreCompressedAudit.audit_({ - ResponseCompression: [ - generateResponse({file: 'index.js', resourceSize: 100 * KB, gzipSize: 90 * KB}), // 10kb & 10% - generateResponse({file: 'index.css', resourceSize: 50 * KB, gzipSize: 37 * KB}), // 13kb & 26% (hit) - generateResponse({file: 'index.json', resourceSize: 2048 * KB, gzipSize: 1024 * KB}), // 1024kb & 50% (hit) - ], - }); - - assert.equal(auditResult.items.length, 2); - }); - - it('passes when all responses are sufficiently optimized', () => { + it('applies a threshold', () => { const auditResult = ResponsesAreCompressedAudit.audit_({ ResponseCompression: [ - generateResponse({file: 'index.js', resourceSize: 1000 * KB, gzipSize: 910 * KB}), // 90kb & 9% - generateResponse({file: 'index.css', resourceSize: 6 * KB, gzipSize: 4.5 * KB}), // 1,5kb & 25% (hit) - generateResponse({file: 'index.json', resourceSize: 10 * KB, gzipSize: 10 * KB}), // 0kb & 0% + generateResponse({file: 'index.js', resourceSize: 1000 * KB, gzipSize: 910 * KB}), // 90kb (hit) + generateResponse({file: 'index.css', resourceSize: 6 * KB, gzipSize: 4.8 * KB}), // 1.2kb + generateResponse({file: 'index2.css', resourceSize: 50 * KB, gzipSize: 37 * KB}), // 13kb (hit) + generateResponse({file: 'index.json', resourceSize: 10 * KB, gzipSize: 10 * KB}), // 0kb generateResponse({file: 'compressed.json', resourceSize: 10 * KB, transferSize: 3 * KB, - gzipSize: 6 * KB}), // 0kb & 0% + gzipSize: 6 * KB}), // 0kb ], }); - assert.equal(auditResult.items.length, 1); + expect(auditResult.items.map(item => item.url)).toEqual(['http://google.com/index.js', 'http://google.com/index2.css']); }); });