How can I monitor the rendering time in a browser?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 06:08:40

问题


I work on an internal corporate system that has a web front-end using Tomcat.

  1. How can I monitor the rendering time of specific pages in a browser (IE6)?
  2. I would like to be able to record the results in a log file (separate log file or the Tomcat access log).

EDIT: Ideally, I need to monitor the rendering on the clients accessing the pages.


回答1:


In case a browser has JavaScript enabled one of the things you could do is to write an inline script and send it first thing in your HTML. The script would do two things:

  1. Record current system time in a JS variable (if you're lucky the time could roughly correspond to the page rendering start time).
  2. Attach JS function to the page onLoad event. This function will then query the current system time once again, subtract the start time from step 1 and send it to the server along with the page location (or some unique ID you could insert into the inline script dynamically on your server).
<script language="JavaScript">
var renderStart = new Date().getTime();
window.onload=function() { 
   var elapsed = new Date().getTime()-renderStart;
   // send the info to the server 
   alert('Rendered in ' + elapsed + 'ms'); 
} 

</script>

... usual HTML starts here ...

You'd need to make sure that the page doesn’t override onload later in the code, but adds to the event handlers list instead.




回答2:


The Navigation Timing API is available in modern browsers (IE9+) except Safari:

function onLoad() { 
  var now = new Date().getTime();
  var page_load_time = now - performance.timing.navigationStart;
  console.log("User-perceived page loading time: " + page_load_time);
}



回答3:


As far as non-invasive techniques are concerned, Hammerhead measures complete load time (including JavaScript execution), albeit in Firefox only.

I've seen usable results when a JavaScript snippet could be added globally to measure the start and end of each page load operation.




回答4:


Have a look at Selenium - they offer a remote control that can automatically start different browsers (e.g. IE6), load pages, test for specific content on the page. At the end reports are generated that also show the rendering times.




回答5:


Since others are posting answers that use other browsers, I guess I will too. Chrome has a very detailed profiling system that breaks down the rendering time of the page and shows the time it took for each step along the way.

As for IE, you might want to consider writing a plugin. There seems to be few tools like this on the market. Maybe you could sell it.




回答6:


On Firefox you can use Firebug to monitor load time. With the YSlow plugin you can even get recommendations how to improve the performance.



来源:https://stackoverflow.com/questions/2516665/how-can-i-monitor-the-rendering-time-in-a-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!