user1120260
user1120260

Reputation: 385

How to get the number of seconds a page loads after all data are shown on the page?

Is it possible to get the TOTAL NUMBER OF SECONDS a page fetch and display the data?

like from the moment I click a link to the moment all data are displayed on the page, done on OnInit, onrender, pageload onprerender and so on..... is it possible?

thanks

Upvotes: 1

Views: 296

Answers (4)

Subhankar
Subhankar

Reputation: 126

yes its possible just you need to add the code in your web.config file and run the application it will prompt you the loading time just after page rendering. Scroll the mouse and get the details.

    <system.web>

        <trace pageOutput="true" requestLimit="10" enabled="true" localOnly="true"        traceMode="SortByTime" mostRecent="true"/>

</system.web>

Note: you need to write the trace part of the code in system.web which already exists in your web.config file.

Upvotes: 1

Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

Send a variable from server having current time in it before displaying page.

On HTML page, run a javascript function on onload(). This function is called after page is loaded. Get the current time again in this function.

Match the both time variables. One sent from server and one in onload() function. You will get the number of seconds.

Upvotes: 0

c2h5oh
c2h5oh

Reputation: 4560

It's possible, but kinda complicated, because the load time from click to full load consists of so many things:

  1. request to the server (connection roundtrip, dns lookup sometimes etc)
  2. request processing server side (this you can measure insude your APS code)
  3. request load till any of the events fire
  4. etc

Long story short is would be impossible to measure it with any single method and combining many would be a pain and would not include all the parts to be measured.

In this particular case the best thing you could do is: bind onclick (on link) an ajax request with current timestamp (millisecond precision) and do a 2nd request, with current timestamp onload and substract the two.

Upvotes: 0

Erwin Moller
Erwin Moller

Reputation: 2408

You can easily check the time PHP needs to run the script: start to finish. Simply store the time at start and end. Look here: http://nl.php.net/manual/en/function.microtime.php

However, this is not the time the user experiences. For example: If PHP needs 0.1 sec to produce the HTML, and the HTML contains 100 big images, the actual pageloading takes a lot longer than 0.1 sec. The actual time the enduser experiences depends on a lot of factors, like webserver that is inbetween (and that need to invoke PHP), networkspeed, caching, etc..

I think your best bet is to approach this via Javascript, and use the onLoad event handler that can be attached to body. Use some external window to do the timing between clicking and the firing of onload.

ALso, keep in mind that result might differ for other visitors with different cache-settings, different networkspeed, etc.. SO you can only get an approximation.

Upvotes: 0

Related Questions