Skip to content

Instantly share code, notes, and snippets.

@overbalance
Last active December 20, 2015 05:59
Show Gist options
  • Save overbalance/6082377 to your computer and use it in GitHub Desktop.
Save overbalance/6082377 to your computer and use it in GitHub Desktop.
// relies on Date.now() which has been supported everywhere modern for years.
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
(function(window) {
// prepare base perf object
if ("performance" in window) {} else {
window.performance = {};
}
if ("now" in window.performance) {} else {
var nowOffset = Date.now();
if ("timing" in window.performance && "navigationStart" in window.performance.timing) {
nowOffset = window.performance.timing.navigationStart;
}
window.performance.now = function() {
return Date.now() - nowOffset;
};
}
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment