使用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.
dongsiju1941
dongsiju1941 toolong
5 年多之前 回复
dongsutao8921
dongsutao8921 toolong
5 年多之前 回复
douhan1860
douhan1860 我不知道为什么有人贬低了(这不是我)。所以你没有直接尝试$.post(),没有事件处理程序?顺便说一下,我刚才注意到在上面显示的客户端代码中你已经包含了两个jQuery副本-你出于某种原因需要版本吗?如果你担心表现,我会尽量避免这种情况。你还说上面的脚本是为“文件准备好”,但它不是,它在窗口加载。
5 年多之前 回复
doubleyou1001
doubleyou1001 所以投票是因为这是一个愚蠢的问题?
5 年多之前 回复
duan1982453
duan1982453 nnnnnn,其中一个要求是将结果存储在一个数据库中,我们跟踪所需的时间。通过控制台可见的信息很棒,但我必须把它放到数据库中。在没有事件处理程序的情况下运行ajax是我之前没有做过的事情。我知道这听起来很愚蠢,但我只是不知道那条路。
5 年多之前 回复
dou7466
dou7466 为什么这个问题会减少投票?我不知道问题是什么。如果我发现问题,我将删除问题。
5 年多之前 回复
doudiewen9435
doudiewen9435 我不知道浏览器的开发控制台是否能满足我的需求。我正在检查出来。
5 年多之前 回复
dsapkqaduj6718493
dsapkqaduj6718493 如果在头文件中包含jquery.js并立即使用一个脚本元素跟随它,该脚本元素使用$.ajax()而不包含在事件处理程序中,那么该请求应该在浏览器甚至到达<body>标记之前提前完成。..但是为什么不使用浏览器的开发控制台的网络(和其他)标签呢?
5 年多之前 回复

1个回答

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.

douzi3756
douzi3756 too long
5 年多之前 回复
douyi8760
douyi8760 哪个浏览器控制台有用吗? 控制台输出可以发送到数据库吗? 是否可以读取正在访问我网站的远程浏览器的控制台? 是否可以使用控制台查看使用我的网站的用户所经历的加载时间? 我的一个要求是看看我的客户加载我的网站需要多长时间,这取决于互联网连接的速度和客户端内存的不同
5 年多之前 回复
donglanying3855
donglanying3855 too long
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐