Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show load time on page

I want to show the users how long the page takes to fully load in the footer of my website.

How do I go about doing this? I assume there is a function that can be used for this?

Not sure what language this type of feature is developed in?

Any help would be appreciated, thanks.

like image 845
sark9012 Avatar asked Aug 10 '14 17:08

sark9012


People also ask

How do I see page load time in Salesforce?

To do this, simply click Page in the Activity section and review the graph. In the example below, you can see that Feed Items and Chatter pages load quickly, while work records load more slowly. You can also use the Lightning Usage App to see how browser performance affects EPT.

How can I see the response time of a website in Chrome?

Chrome -> Right Click -> Inspect Element -> Network Tab. When you load a page there is a nice report for the timeline of the page showing the actual page load time, css, js etc. load times.

What is webpage load time?

Page load time is the time it takes for a page to load, measured from navigation start to the start of the load event. let time = performance. timing; let pageloadtime = time.


3 Answers

You may try like this:

$starttime = microtime(true); // Top of page
// Code
$endtime = microtime(true); // Bottom of page

printf("Page loaded in %f seconds", $endtime - $starttime );

As commented by Ed Heal you need to use JavaScript as network/proxy/routes need to be factored in.

Also you may try this approach as well:

From the source

Put the following code at the very top of your PHP page (if you measure the time needed for particular part of the code put this right before that PHP code part)

<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
?>

The following code has to be put at the very end of the web page (or the end of the PHP code part)

<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>
like image 132
Rahul Tripathi Avatar answered Oct 04 '22 19:10

Rahul Tripathi


2 simple steps to show load time on your page:

1. Put this code at beginning of your page:

 <?php $start_time = microtime(true); ?>

2. Put this code at the end of your page:

This page was generated in <?php echo(number_format(microtime(true) - $start_time, 2)); ?> seconds.
like image 33
Marwan Salim Avatar answered Oct 04 '22 20:10

Marwan Salim


You need two times: the starttime and the endtime. Using JavaScript the starttime can only be approximated because the script will only fire when it is loaded, not before. This means that you will not measure stuff like DNS looking, initial latency and initial downloading. If you're fine with this limitation do this:

  1. In the head of the page determine the current time using an inline script
  2. On the firing of the onload determine the current time again
  3. subtract the first time from the second and then you have the total time it took to load the page

Another caveat: Stuff that gets loaded via ajax is not measured here either. The onload fires before the ajax stuff runs.

like image 27
Koen Peters Avatar answered Oct 04 '22 19:10

Koen Peters