angular-performance
Version:
AngularJS directive to measure perceived page load time
1 lines • 789 B
JavaScript
var perf=angular.module("performance",[]);perf.directive("performance",[function(){return{restrict:"A",link:function(e,n,r){var i=(new Date).getTime();var t=[];e.$on("PERF_DONE",function(e,n){var a=t.indexOf(n);if(a>=0)t.splice(a,1);if(a>=0&&t.length==0){var o=(new Date).getTime()-i;var c=0;if(window.performance){c=window.performance.timing.loadEventEnd-window.performance.timing.navigationStart}var f=new Image;f.src=r.performanceBeacon+"?content="+o+"&initial="+c+"&name="+r.performance}});e.$on("PERF_REGISTER",function(e,n){t.push(n)})}}}]);perf.directive("performanceLoaded",["$timeout",function(e){return{restrict:"A",link:function(n,r,i){e(function(){n.$emit("PERF_REGISTER",n.$id)},0);var t=n.$watch(i.performanceLoaded,function(e,r){if(e){n.$emit("PERF_DONE",n.$id);t()}})}}}]);