doujun7161 2015-06-20 05:59
浏览 55
已采纳

使用Ajax定时浏览器

Objective: time how long the browser takes loading a page, from the earliest point possible in its loading process, starting as soon as possible after the server has started sending it data.

Context: new feature to existing set of scripts that stores web performance data. Most of the existing app is on the server-side, the new feature is for the client side.

This is where I need help. I am looking for the earliest event to use for a script like this, which is using

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">

   $(document).ready(function(){
        $.post("<?= $baseURL?><?= $pageparts.$common ?>/saveData.php",
            {
              typeOfRecord:"docready",
              thisURL:"<?= $thisURL ?>"
            },
            function(data,status){
              ;
            }
        );
    });
</script>

Here is a screenshot of what results look like. I am looking for the earliest and lastest events or points in the browser load process, starting from the time it starts receiving data from the server in response to the request it has made. Timestamps and split times on server and client side of generating a web page.

You can run a sample at this link

Here is what I am having a problem figuring out:

  1. What events should be used to record the earliest moment when the browser is receiving and starting to render the page source sent to it by the server, and the last thing done by the browser to be considered loaded.
  • 写回答

1条回答

  • doulian8742 2015-06-22 07:03
    关注

    If you include jquery.js in the header and follow it immediately with a script element that uses $.ajax() (or $.post() or whatever) not wrapped in an event handler, then that ajax request should be made immediately at that point, before the browser even gets to the <body> tag.

    So assuming the JS code you show is in the header you could add an ajax call just before where you bind the document ready handler.

    Note that of course the browser would have to download jQuery before getting to your script, so if you want to get in even before that you'd have to code the ajax call yourself without jQuery methods, in a script element that is included before jQuery.

    You may also want to look into using your browser's dev console's network (and other) tab(s) for this type of thing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误