Skip to content

Commit

Permalink
DNS and Connect timings (resolves #477)
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Feb 23, 2019
1 parent de21572 commit 5d76840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/windowPerformance/windowPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ module.exports = function(phantomas) {
phantomas.setMetric('domContentLoadedEnd'); // @desc time it took to finish handling of onDOMReady event @unreliable
phantomas.setMetric('domComplete'); // @desc time it took to load all page resources, the loading spinner has stopped spinning

// get values from Resource Timing API (issue #477)
phantomas.setMetric('performanceTimingConnect'); // @desc time it took to connect to the server before making the first HTTP request
phantomas.setMetric('performanceTimingDNS'); // @desc time it took to resolve the domain before making the first HTTP request
phantomas.setMetric('performanceTimingPageLoad'); // @desc time it took to fully load the page
phantomas.setMetric('performanceTimingTTFB'); // @desc time it took to receive the first byte of the first HTTP response

// backend vs frontend time
phantomas.setMetric('timeBackend'); // @desc time to the first byte compared to the total loading time [%]
phantomas.setMetric('timeFrontend'); // @desc time to window.load compared to the total loading time [%]
Expand All @@ -41,6 +47,12 @@ module.exports = function(phantomas) {
phantomas.setMetric('domContentLoadedEnd', timing.domContentLoadedEventEnd - base);
phantomas.setMetric('domComplete', timing.domComplete - base);

// see #477
phantomas.setMetric('performanceTimingConnect', timing.connectEnd - timing.connectStart);
phantomas.setMetric('performanceTimingDNS', timing.domainLookupEnd - timing.domainLookupStart);
phantomas.setMetric('performanceTimingPageLoad', timing.loadEventStart - timing.navigationStart);
phantomas.setMetric('performanceTimingTTFB', timing.responseStart - timing.navigationStart);

/**
* Emit metrics with backend vs frontend time
*
Expand Down
3 changes: 3 additions & 0 deletions test/integration-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@
domainsToDomContentLoaded: 2
requestsToDomComplete: 3
domainsToDomComplete: 2
# test are made using a HTTP server running locally, it should be pretty fast to connect to it
performanceTimingConnect: 0
performanceTimingDNS: 0
offenders:
domainsToDomContentLoaded:
- { domain: '127.0.0.1', requests: 2 }
Expand Down

0 comments on commit 5d76840

Please sign in to comment.