From bbe2191fdc98e958d0eef3d26e749fd531169106 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 19 Jul 2017 14:53:04 -0700 Subject: [PATCH] perf(uses-http2): check protocol first (#2701) --- lighthouse-core/audits/dobetterweb/uses-http2.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/audits/dobetterweb/uses-http2.js b/lighthouse-core/audits/dobetterweb/uses-http2.js index 58a3fa0d969d..0caf92519ea6 100644 --- a/lighthouse-core/audits/dobetterweb/uses-http2.js +++ b/lighthouse-core/audits/dobetterweb/uses-http2.js @@ -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,