Skip to content

Commit

Permalink
perf(uses-http2): check protocol first (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and brendankenny committed Jul 19, 2017
1 parent 4143aac commit bbe2191
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lighthouse-core/audits/dobetterweb/uses-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class UsesHTTP2Audit extends Audit {

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

0 comments on commit bbe2191

Please sign in to comment.