Last active
January 15, 2017 23:15
-
-
Save choonkending/e21380a75bf02c08cdc206f1b0950e0a to your computer and use it in GitHub Desktop.
Print navigation timing in your browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const events = [ 'domLoading', 'domInteractive', 'domContentLoadedEventEnd', 'domComplete', 'loadEventEnd' ]; | |
const startEvent = 'navigationStart'; | |
const timing = performance.timing; | |
const compose = (f, g) => x => f(g(x)); | |
const timeFromNavigationStart = event => differenceInSeconds(timing[event], timing[startEvent]); | |
const differenceInSeconds = (t1, t2) => (t1 - t2) / 1000; | |
const sanitizeTime = t => (t > 0) ? t : 'N/A - Has not fired yet - please run console log again'; | |
const getTimeDifference = compose(sanitizeTime, timeFromNavigationStart); | |
const buildEventsArray = events => events.map((event) => { | |
const timeDifference = getTimeDifference(event); | |
return new Event(event, timeDifference); | |
}); | |
class Event { | |
constructor(navigationTiming, seconds) { | |
this.navigationTiming = navigationTiming; | |
this.seconds = seconds; | |
} | |
} | |
console.table(buildEventsArray(events)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment