From ebe1fad5c08654670a2844fcdf69de6df7a5dee8 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Fri, 12 May 2017 06:53:49 +0200 Subject: [PATCH] Rename time to first byte --- ...-to-firstbyte.js => time-to-first-byte.js} | 68 ++++++++++--------- lighthouse-core/config/default.js | 12 ++-- ...yte-test.js => time-to-first-byte-test.js} | 2 +- 3 files changed, 43 insertions(+), 39 deletions(-) rename lighthouse-core/audits/{time-to-firstbyte.js => time-to-first-byte.js} (65%) rename lighthouse-core/test/audits/{time-to-firstbyte-test.js => time-to-first-byte-test.js} (97%) diff --git a/lighthouse-core/audits/time-to-firstbyte.js b/lighthouse-core/audits/time-to-first-byte.js similarity index 65% rename from lighthouse-core/audits/time-to-firstbyte.js rename to lighthouse-core/audits/time-to-first-byte.js index 15e7ff089fba..d7013cd5c9c7 100644 --- a/lighthouse-core/audits/time-to-firstbyte.js +++ b/lighthouse-core/audits/time-to-first-byte.js @@ -31,12 +31,12 @@ class TTFBMetric extends Audit { static get meta() { return { category: 'Performance', - name: 'time-to-firstbyte', + name: 'time-to-first-byte', description: 'Time To First Byte (TTFB)', informative: true, helpText: 'Time To First Byte identifies the time at which your server sends a response.' + '[Learn more](https://developers.google.com/web/tools/chrome-devtools/network-performance/issues).', - requiredArtifacts: ['networkRecords'] + requiredArtifacts: ['devtoolsLogs'] }; } @@ -51,37 +51,49 @@ class TTFBMetric extends Audit { * @return {!AuditResult} */ static audit(artifacts) { - const networkRecords = artifacts.networkRecords[Audit.DEFAULT_PASS]; - const results = []; - const walk = (node) => { - const children = Object.keys(node); - - children.forEach(id => { - const child = node[id]; + const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; + + return artifacts.requestNetworkRecords(devtoolsLogs).then( + networkRecords => artifacts.requestCriticalRequests(networkRecords) + .then(criticalRequests => [ + criticalRequests, + networkRecords + ]) + ).then(([criticalRequests, networkRecords]) => { + const results = []; + let displayValue; - const networkRecord = networkRecords.find(record => record._requestId === id); + criticalRequests.forEach(request => { + const networkRecord = networkRecords.find(record => record._requestId === request.id); - if (networkRecord) { + if (networkRecord && networkRecord._timing) { const ttfb = TTFBMetric.caclulateTTFB(networkRecord); results.push({ url: URL.getDisplayName(networkRecord._url), ttfb: `${Math.round(ttfb).toLocaleString()} ms`, - rawTTFB: ttfb + rawTTFB: ttfb, }); } - - if (child.children) { - walk(child.children); - } }); - }; - - return artifacts.requestCriticalRequestChains(networkRecords).then(tree => { - walk(tree); const recordsOverBudget = results.filter(row => - row.rawTTFB > TTFB_THRESHOLD + TTFB_THRESHOLD_BUFFER); - let displayValue; + row.rawTTFB > TTFB_THRESHOLD + TTFB_THRESHOLD_BUFFER + ); + const extendedInfo = { + formatter: Formatter.SUPPORTED_FORMATS.TABLE, + value: { + results, + tableHeadings: { + url: 'Request URL', + ttfb: 'Time To First Byte', + }, + }, + }; + + const details = Audit.makeV2TableDetails([ + {key: 'url', itemType: 'url', text: 'URL'}, + {key: 'ttfb', itemType: 'text', text: 'Time To First Byte (ms)'}, + ], recordsOverBudget); if (recordsOverBudget.length) { displayValue = recordsOverBudget.length + @@ -90,17 +102,9 @@ class TTFBMetric extends Audit { return { rawValue: recordsOverBudget.length === 0, + details, displayValue, - extendedInfo: { - formatter: Formatter.SUPPORTED_FORMATS.TABLE, - value: { - results, - tableHeadings: { - url: 'Request URL', - ttfb: 'Time To First Byte', - }, - }, - }, + extendedInfo, }; }); } diff --git a/lighthouse-core/config/default.js b/lighthouse-core/config/default.js index 88645636a260..3561304673d3 100644 --- a/lighthouse-core/config/default.js +++ b/lighthouse-core/config/default.js @@ -57,9 +57,9 @@ module.exports = { "load-fast-enough-for-pwa", "speed-index-metric", "estimated-input-latency", - // "time-to-firstbyte", "first-interactive", "consistently-interactive", + "time-to-first-byte", "time-to-interactive", "user-timings", "critical-request-chains", @@ -164,10 +164,10 @@ module.exports = { "expectedValue": 100, "weight": 1 }, - // "time-to-firstbyte": { - // "expectedValue": true, - // "weight": 1 - // }, + "time-to-first-byte": { + "expectedValue": true, + "weight": 1 + }, "time-to-interactive": { "expectedValue": 100, "weight": 1 @@ -664,7 +664,7 @@ module.exports = { {"id": "uses-optimized-images", "weight": 0, "group": "perf-hint"}, {"id": "uses-request-compression", "weight": 0, "group": "perf-hint"}, {"id": "uses-responsive-images", "weight": 0, "group": "perf-hint"}, - // {"id": "time-to-firstbyte", "weight": 0, "group": "perf-hint"}, + {"id": "time-to-first-byte", "weight": 0, "group": "perf-hint"}, {"id": "total-byte-weight", "weight": 0, "group": "perf-info"}, {"id": "dom-size", "weight": 0, "group": "perf-info"}, {"id": "critical-request-chains", "weight": 0, "group": "perf-info"}, diff --git a/lighthouse-core/test/audits/time-to-firstbyte-test.js b/lighthouse-core/test/audits/time-to-first-byte-test.js similarity index 97% rename from lighthouse-core/test/audits/time-to-firstbyte-test.js rename to lighthouse-core/test/audits/time-to-first-byte-test.js index c0976bce1d29..5acec16ff7ff 100644 --- a/lighthouse-core/test/audits/time-to-firstbyte-test.js +++ b/lighthouse-core/test/audits/time-to-first-byte-test.js @@ -15,7 +15,7 @@ */ 'use strict'; -const TimeToFirstByte = require('../../audits/time-to-firstbyte.js'); +const TimeToFirstByte = require('../../audits/time-to-first-byte.js'); const assert = require('assert'); /* eslint-env mocha */