Skip to content

Commit bbe2191

Browse files
patrickhulcebrendankenny
authored andcommitted
perf(uses-http2): check protocol first (#2701)
1 parent 4143aac commit bbe2191

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lighthouse-core/audits/dobetterweb/uses-http2.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class UsesHTTP2Audit extends Audit {
4343

4444
// Filter requests that are on the same host as the page and not over h2.
4545
const resources = networkRecords.filter(record => {
46+
// test the protocol first to avoid (potentially) expensive URL parsing
47+
const isOldHttp = /HTTP\/[01][\.\d]?/i.test(record.protocol);
48+
if (!isOldHttp) return false;
4649
const requestHost = new URL(record._url).host;
47-
const sameHost = requestHost === finalHost;
48-
const notH2 = /HTTP\/[01][\.\d]?/i.test(record.protocol);
49-
return sameHost && notH2;
50+
return requestHost === finalHost;
5051
}).map(record => {
5152
return {
5253
protocol: record.protocol,

0 commit comments

Comments
 (0)