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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退