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

add custom api for adding ttfmp from fragments #214

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator Author

@vigneshshanmugam vigneshshanmugam Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just keeping it as ttfmp to avoid the name collision in future once first-meaningful-paint is added to Paint Timing

}
// 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think addPerfEntry.bind(null, 'ttfmp') is shorter than the current implementation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bind is slow in older versions of v8 (older browsers might suffer from this). Thats why i went for explicit function. But, its just one time call so shouldn't matter much.

getEntries: getEntries
};
})(window.document, window.performance);