performance.timing.loadEventEnd set to 0 when using JSONP

386 views Asked by At

I want to count the time taken for page load once the page is received from the server, so I use the remainder of loadEventEnd and responseEnd.

But in my code I also use JSONP technology, and when I use "get function getJson()" the loadEventEnd return 0.

var getJson = function() {
document.getElementsByTagName('body')[0].appendChild((function(){
      var sc = document.createElement('script');
      sc.type = 'text/javascript';  sc.src = 'http://www.google.com/?callback=json123';
      return sc;
   })());
};

window.onload = new function(){
   getJson(); // problem !!!
   setTimeout(function(){
      var t = performance.timing;
      console.log(t.loadEventEnd - t.responseEnd);
   }, 0);
}
0

There are 0 answers