From ca8cd7346312c2fb8a5c241720971ca368466b15 Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Sun, 31 Mar 2024 14:59:56 -0700 Subject: [PATCH 1/3] Rename TTFBAttribution fields to duration --- src/attribution/onTTFB.ts | 16 ++++++++-------- src/types/ttfb.ts | 8 ++++---- test/e2e/onTTFB-test.js | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/attribution/onTTFB.ts b/src/attribution/onTTFB.ts index 8228462a..fa99e1cb 100644 --- a/src/attribution/onTTFB.ts +++ b/src/attribution/onTTFB.ts @@ -42,20 +42,20 @@ const attributeTTFB = (metric: TTFBMetric): void => { ); (metric as TTFBMetricWithAttribution).attribution = { - waitingTime: dnsStart, - dnsTime: connectStart - dnsStart, - connectionTime: requestStart - connectStart, - requestTime: metric.value - requestStart, + waitingDuration: dnsStart, + dnsDuration: connectStart - dnsStart, + connectionDuration: requestStart - connectStart, + requestDuration: metric.value - requestStart, navigationEntry: navigationEntry, }; return; } // Set an empty object if no other attribution has been set. (metric as TTFBMetricWithAttribution).attribution = { - waitingTime: 0, - dnsTime: 0, - connectionTime: 0, - requestTime: 0, + waitingDuration: 0, + dnsDuration: 0, + connectionDuration: 0, + requestDuration: 0, }; }; diff --git a/src/types/ttfb.ts b/src/types/ttfb.ts index 35a7f8c3..be913c55 100644 --- a/src/types/ttfb.ts +++ b/src/types/ttfb.ts @@ -35,21 +35,21 @@ export interface TTFBAttribution { * DNS lookup begins. This includes redirects, service worker startup, and * HTTP cache lookup times. */ - waitingTime: number; + waitingDuration: number; /** * The total time to resolve the DNS for the current request. */ - dnsTime: number; + dnsDuration: number; /** * The total time to create the connection to the requested domain. */ - connectionTime: number; + connectionDuration: number; /** * The time time from when the request was sent until the first byte of the * response was received. This includes network time as well as server * processing time. */ - requestTime: number; + requestDuration: number; /** * The `navigation` entry of the current page, which is useful for diagnosing * general page load issues. This can be used to access `serverTiming` for example: diff --git a/test/e2e/onTTFB-test.js b/test/e2e/onTTFB-test.js index a3b43c9a..95296e1d 100644 --- a/test/e2e/onTTFB-test.js +++ b/test/e2e/onTTFB-test.js @@ -261,19 +261,19 @@ describe('onTTFB()', async function () { const navEntry = ttfb.entries[0]; assert.strictEqual( - ttfb.attribution.waitingTime, + ttfb.attribution.waitingDuration, navEntry.domainLookupStart, ); assert.strictEqual( - ttfb.attribution.dnsTime, + ttfb.attribution.dnsDuration, navEntry.connectStart - navEntry.domainLookupStart, ); assert.strictEqual( - ttfb.attribution.connectionTime, + ttfb.attribution.connectionDuration, navEntry.requestStart - navEntry.connectStart, ); assert.strictEqual( - ttfb.attribution.requestTime, + ttfb.attribution.requestDuration, navEntry.responseStart - navEntry.requestStart, ); @@ -303,22 +303,22 @@ describe('onTTFB()', async function () { const navEntry = ttfb.entries[0]; assert.strictEqual( - ttfb.attribution.waitingTime, + ttfb.attribution.waitingDuration, Math.max(0, navEntry.domainLookupStart - activationStart), ); assert.strictEqual( - ttfb.attribution.dnsTime, + ttfb.attribution.dnsDuration, Math.max(0, navEntry.connectStart - activationStart) - Math.max(0, navEntry.domainLookupStart - activationStart), ); assert.strictEqual( - ttfb.attribution.connectionTime, + ttfb.attribution.connectionDuration, Math.max(0, navEntry.requestStart - activationStart) - Math.max(0, navEntry.connectStart - activationStart), ); assert.strictEqual( - ttfb.attribution.requestTime, + ttfb.attribution.requestDuration, Math.max(0, navEntry.responseStart - activationStart) - Math.max(0, navEntry.requestStart - activationStart), ); @@ -346,10 +346,10 @@ describe('onTTFB()', async function () { assert.strictEqual(ttfb.navigationType, 'back-forward-cache'); assert.strictEqual(ttfb.entries.length, 0); - assert.strictEqual(ttfb.attribution.waitingTime, 0); - assert.strictEqual(ttfb.attribution.dnsTime, 0); - assert.strictEqual(ttfb.attribution.connectionTime, 0); - assert.strictEqual(ttfb.attribution.requestTime, 0); + assert.strictEqual(ttfb.attribution.waitingDuration, 0); + assert.strictEqual(ttfb.attribution.dnsDuration, 0); + assert.strictEqual(ttfb.attribution.connectionDuration, 0); + assert.strictEqual(ttfb.attribution.requestDuration, 0); assert.strictEqual(ttfb.attribution.navigationEntry, undefined); }); }); From 039f729f6c576bc4a0f08ac22cb4b5d0f9f93a0e Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Mon, 1 Apr 2024 10:02:54 -0700 Subject: [PATCH 2/3] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5979cdb3..f7f59e3a 100644 --- a/README.md +++ b/README.md @@ -1028,21 +1028,21 @@ interface TTFBAttribution { * DNS lookup begins. This includes redirects, service worker startup, and * HTTP cache lookup times. */ - waitingTime: number; + waitingDuration: number; /** * The total time to resolve the DNS for the current request. */ - dnsTime: number; + dnsDuration: number; /** * The total time to create the connection to the requested domain. */ - connectionTime: number; + connectionDuration: number; /** * The time time from when the request was sent until the first byte of the * response was received. This includes network time as well as server * processing time. */ - requestTime: number; + requestDuration: number; /** * The `navigation` entry of the current page, which is useful for diagnosing * general page load issues. This can be used to access `serverTiming` for example: From 1330728bcfdce2357fbda48f60ffc900d2046b0b Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Mon, 1 Apr 2024 12:40:02 -0700 Subject: [PATCH 3/3] Update src/types/ttfb.ts Co-authored-by: Rick Viscomi --- src/types/ttfb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/ttfb.ts b/src/types/ttfb.ts index be913c55..719d4310 100644 --- a/src/types/ttfb.ts +++ b/src/types/ttfb.ts @@ -45,7 +45,7 @@ export interface TTFBAttribution { */ connectionDuration: number; /** - * The time time from when the request was sent until the first byte of the + * The total time from when the request was sent until the first byte of the * response was received. This includes network time as well as server * processing time. */