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.

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

报告相同问题?