Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
add custom api for adding ttfmp from fragments (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam authored Jan 11, 2018
1 parent effbe16 commit 31ced26
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,29 @@
}
/*
* Custom Performance entries that can be added from fragments
* Its need because Browsers currently does not allow expose any API to add
* It's needed because browsers currently do not expose an API to add
* custom timing information to performance entries
*/
function addPerfEntry(name, duration) {
// Should not add to entries when Navigation timing is not supported.
if (!'timing' in perf) {
return;
}
// duplicate entries are not handled to keep the API
// similar to PerformanceEntry Object
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry
entries.push({
name: name,
duration: Number(duration),
entryType: 'tailor',
startTime: perf.now() || Date.now() - perf.timing.navigationStart
});
}
// Unique API that allows fragments to specify the
// time to first meaningul paint of the page
function addTTFMPEntry(duration) {
addPerfEntry('ttfmp', duration);
}
// Retrive the added entries from fragments for monitoring
function getEntries() {
return entries;
Expand All @@ -203,6 +211,7 @@
onAfterInit: assignHook('onAfterInit'),
onDone: assignHook('onDone'),
addPerfEntry: addPerfEntry,
addTTFMPEntry: addTTFMPEntry,
getEntries: getEntries
};
})(window.document, window.performance);

0 comments on commit 31ced26

Please sign in to comment.