-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
72 lines (59 loc) · 1.89 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* HTTP 1.1 vs HTTP/2 vs HTTP/2 server push test
* Uses logos from http://e-kaubanduseliit.ee/e-smaspaev/ ... as we were supporting the campaign when I wrote the test
*
* User: [email protected]
* Date: 13.05.2016
* Time: 19:24
*/
require_once 'merchants.inc.php';
// this set has been optimized with ImageOptim, use /img_original for larger files
$img_path = '/img_optimized';
$html = '';
$header = [];
$cachekiller = bin2hex( random_bytes( 5 ) );
foreach ( $merchants as $alt => $image ) {
$html .= "<img src='$img_path/$image?ck$cachekiller' width='175' height='75' alt='$alt'>";
$header[] = "<$img_path/$image?ck$cachekiller>; rel=preload; as=image";
}
if ( isset( $_GET['push'] ) ) {
// header( "Link: $header" );
foreach ($header as $link) {
header( "Link: $link", false );
}
}
?><!DOCTYPE html>
<html lang="et">
<head>
<meta charset="UTF-8">
<title>E-smaspäev!</title>
</head>
<body>
<div class="timing">
<p>Load time: <span id="loadTime"></span></p>
</div>
<?php echo $html; ?>
<script>
window.addEventListener("load", function () {
setTimeout(function () {
var performance = window.performance || window.webkitPerformance || window.msPerformance || window.mozPerformance;
if (performance === undefined) {
return false;
}
var loadTime = performance.timing.loadEventEnd - performance.timing.fetchStart;
console.log(loadTime);
document.getElementById("loadTime").textContent = loadTime + 'ms';
// well, we obviously are able to log the results :-)
// you can find your log named by you IP address as logs/timelog_xxx.xxx.xxx.xxx.csv
if (window.location.search.indexOf('log') > -1) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "loghandler.php");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify({loadTime: loadTime}));
}
}, 0);
}, false);
</script>
</body>
</html>