Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
Created April 27, 2012 18:37
Show Gist options
  • Save JasonStoltz/2511617 to your computer and use it in GitHub Desktop.
Save JasonStoltz/2511617 to your computer and use it in GitHub Desktop.
Steve souders nav timing code as bookmarklet
javascript:function formatTime(a){var b=new Date(a);return b.getHours()+":"+("0"+b.getMinutes()).slice(-2)+":"+("0"+b.getSeconds()).slice(-2)+"."+("00"+b.getMilliseconds()).slice(-3)}function doTime(a,b,c){if(!a){return""}if("undefined"===typeof b){if("undefined"===typeof performance.timing[a]){return"";return a+" is undefined"}else{b=performance.timing[a];c=undefined}}if(0===b){return"";return a+" is 0"}else if(b&&"undefined"===typeof c){return formatTime(b)+" = "+a+" ("+(b-gStart)+")"}else if(b&&c){return a+" = "+(c-b)+" ms"}}function doTimeln(a,b,c){var d=doTime(a,b,c);return d?d+"\n":""}function doNavTiming(){if("undefined"===typeof performance){alert("ERROR: Navigation timing API was not found.")}else{gStart=performance.timing.navigationStart;var a=doTimeln("total time",performance.timing.navigationStart,performance.timing.loadEventEnd)+doTimeln("dns",performance.timing.domainLookupStart,performance.timing.domainLookupEnd)+doTimeln("connect",performance.timing.connectStart,performance.timing.connectEnd)+doTimeln("ttfb",performance.timing.connectEnd,performance.timing.responseStart)+doTimeln("HTML",performance.timing.responseStart,performance.timing.responseEnd)+doTimeln("frontend",performance.timing.responseEnd,performance.timing.loadEventStart)+"\n"+doTimeln("navigationStart")+doTimeln("unloadEventStart")+doTimeln("unloadEventEnd")+doTimeln("redirectStart")+doTimeln("redirectEnd")+doTimeln("fetchStart")+doTimeln("domainLookupStart")+doTimeln("domainLookupEnd")+doTimeln("connectStart")+doTimeln("connectEnd")+doTimeln("secureConnectionStart")+doTimeln("requestStart")+doTimeln("responseStart")+doTimeln("responseEnd")+doTimeln("domLoading")+doTimeln("domInteractive")+doTimeln("domContentLoadedEventStart")+doTimeln("domContentLoadedEventEnd")+doTimeln("domComplete")+doTimeln("loadEventStart")+doTimeln("loadEventEnd")+"";console.log(a)}}doNavTiming();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment