Skip to content

Commit

Permalink
Rename time to first byte
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed May 12, 2017
1 parent 00373ed commit ebe1fad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']
};
}

Expand All @@ -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 +
Expand All @@ -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,
};
});
}
Expand Down
12 changes: 6 additions & 6 deletions lighthouse-core/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit ebe1fad

Please sign in to comment.