Skip to content

Commit

Permalink
core(uses-text-compression): remove 10% savings threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Aug 23, 2024
1 parent 1b44c5c commit 9953f4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
9 changes: 2 additions & 7 deletions core/audits/byte-efficiency/uses-text-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
}

Expand Down
35 changes: 12 additions & 23 deletions core/test/audits/byte-efficiency/uses-text-compression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});

0 comments on commit 9953f4d

Please sign in to comment.