如何监视在浏览器中渲染时间? [英] How can I monitor the rendering time in a browser?

查看:2067
本文介绍了如何监视在浏览器中渲染时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,有一个Web前端作为其接口之一的企业内部系统上工作。

该网站的前端供应了使用Tomcat。

如何监控特定页面的渲染时间在浏览器(IE6)?

我希望能够记录在日志文件中的结果(单独的日志文件或Tomcat的访问日志)。

编辑:理想情况下,我需要监控访问网页客户端的渲染


解决方案

在情况下,浏览器中启用JavaScript的你可以做的事情之一就是编写一个内嵌脚本,并将其发送第一件事情在你的HTML。该脚本会做两件事情:


  1. 记录当前的系统时间在一个JS变量(如果你是幸运的时候可以大致对应的页面渲染开始时间)。

  2. 附加功能JS在页面onLoad事件。然后,此功能将再次查询当前系统时间,从第1步减去开始时间,并将它发送到服务器的页面位置沿(或一些独特的ID,你可以在你的服务器上动态地插入内嵌脚本)。

 < SCRIPT LANGUAGE =JavaScript的>
VAR renderStart =新的日期()的getTime()。
在window.onload =函数(){
   VAR经过=新的日期()的getTime() - renderStart。
   //将信息发送到服务器
   警报(+经过+'MS'在渲染');
}< / SCRIPT>...通常的HTML从这里开始......

您就需要确保该页面不会在code onload事件后覆盖,但增加了事件处理程序列表,而不是

I work on an internal corporate system that has a web front-end as one of its interfaces.

The web front-end is served up using Tomcat.

How can I monitor the rendering time of specific pages in a browser (IE6)?

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.

解决方案

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.

这篇关于如何监视在浏览器中渲染时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆