如何监控浏览器中的渲染时间?

发布于 2024-08-26 22:33:52 字数 168 浏览 6 评论 0原文

我负责一个内部公司系统,该系统具有使用 Tomcat 的 Web 前端。

  1. 如何监控浏览器(IE6)中特定页面的渲染时间?
  2. 我希望能够将结果记录在日志文件(单独的日志文件或 Tomcat 访问日志)中。

理想情况下,我需要监视访问页面的客户端上的渲染。

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).

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

征﹌骨岁月お 2024-09-02 22:33:53

导航计时 API 适用于所有现代浏览器。

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);
}

The Navigation Timing API is available in all modern browsers.

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);
}
怪我入戏太深 2024-09-02 22:33:53

如果浏览器启用了 JavaScript,您可以做的一件事就是编写内联脚本并在 HTML 中首先将其发送。该脚本会做两件事:

  1. 在 JS 变量中记录当前系统时间(如果幸运的话,该时间可能大致对应于页面渲染开始时间)。
  2. 将 JS 函数附加到页面 onLoad 事件。然后,该函数将再次查询当前系统时间,减去步骤 1 中的开始时间,并将其与页面位置(或者可以动态插入到服务器上的内联脚本中的一些唯一 ID)一起发送到服务器。
<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 ...

您需要确保页面不会在代码中重写 onload,而是添加到事件处理程序列表中。

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.

心舞飞扬 2024-09-02 22:33:53

就非侵入性技术而言,Hammerhead 测量完整的加载时间(包括 JavaScript 执行),尽管仅限火狐浏览器。

当可以全局添加 JavaScript 代码片段来测量每个页面加载操作的开始和结束时,我已经看到了可用的结果。

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.

濫情▎り 2024-09-02 22:33:53

看看Selenium - 他们提供了一个远程控制,可以自动启动不同的浏览器(例如IE6),加载页面,测试页面上的特定内容。最后生成的报告还显示渲染时间。

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.

Bonjour°[大白 2024-09-02 22:33:53

由于其他人正在发布使用其他浏览器的答案,我想我也会的。 Chrome 有一个非常详细的分析系统,可以细分页面的渲染时间并显示每个页面所花费的时间一路走来。

至于IE,你可能要考虑编写一个插件。市场上类似的工具似乎很少。也许你可以卖掉它。

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.

甜`诱少女 2024-09-02 22:33:53

在 Firefox 上,您可以使用 Firebug 来监控加载时间。使用 YSlow 插件,您甚至可以获得如何提高性能的建议。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文