Last active
December 18, 2015 01:48
-
-
Save bijayrungta/5706171 to your computer and use it in GitHub Desktop.
This Snippet demonstrates how Redirection time is also counted towards User perceived Page Load time using
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!empty($_GET['redir']) && $_GET['redir'] < 11) { | |
sleep(1); | |
$url = '?redir=' . ($_GET['redir'] + 1); | |
header("Location: {$url}"); | |
exit; | |
} | |
?><!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<script type="text/javascript"> | |
function onLoad() { | |
var now = new Date().getTime(); | |
var page_load_time = now - performance.timing.navigationStart; | |
alert("User-perceived page loading time: " + page_load_time); | |
} | |
</script> | |
</head> | |
<body onload="onLoad()"> | |
<!- Main page body goes from here. --> | |
<div style="clear:both"></div> | |
<ul> | |
<li><a href="?redir=1">Click Here to have a ride!!</a></li> | |
<li><a href="?" onclick="var elm = this; setTimeout(function() { window.location = elm.href; }, 1000); return false;">Click Here to see effect of waiting after Click!!</a></li> | |
<li><a href="?">Click Here to check page without redirection!!</a></li> | |
</ul> | |
<ul> | |
<li>User-perceived page loading time (Without Redirection): ~1,369ms</li> | |
<li>User-perceived page loading time (With Redirection 10 times waiting for 1 sec each time): ~11,812ms</li> | |
</ul> | |
<p>This Snippet demonstrates how Redirection time is also counted towards | |
User perceived Page Load time using | |
<a target="_blank" href="http://www.w3.org/TR/navigation-timing/#sec-navigation-timing-introduction">Navigation Timing API</a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment