Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: user5f44c
Added: May 14, 2020 12:28 PM
Modified: May 14, 2020 1:10 PM
Views: 137
Tags: no tags
  1. <script>
  2. (function(){
  3. var  perfData = window.performance.timing;
  4. var time = perfData.domInteractive - perfData.responseStart;
  5. var n = sessionStorage.getItem('on_load_counter');
  6.  if (n === null) {
  7.     n = 0;
  8. }
  9.  n++;
  10.  sessionStorage.setItem("on_load_counter", n);
  11. var getTime = parseInt(sessionStorage.getItem("time"));
  12.   if(parseInt(n) === 1){
  13.  sessionStorage.setItem("time", time );
  14.   }  
  15.   if(parseInt(n) > 1){
  16.  sessionStorage.setItem("time", time + getTime );  
  17. }
  18.  var avgLoadTime = parseInt(sessionStorage.getItem('time'))/parseInt(n);
  19.  sessionStorage.setItem("avgTime", avgLoadTime );  
  20. })
  21.   ();
  22. </script>