-
Notifications
You must be signed in to change notification settings - Fork 40
/
pageload.html
106 lines (103 loc) · 2.25 KB
/
pageload.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1">
<title>Page Load Responsiveness test</title>
<style>
body, html {
margin: 0;
height: 100%;
width: 100%;
background: lightblue;
overflow: hidden;
}
#header {
padding: 8px;
}
#stime {
width: 30px;
}
#container {
position: absolute;
width: 100%;
top: 200px;
bottom: 1px;
}
iframe {
position: relative;
height: 100%;
width: 100%;
border: 0;
}
</style>
</head>
<body>
<div id=header>
<b>Page Load Responsiveness Test</b><br>
Url: <input id=url><input type=submit value=Go id=go><br>
Stop: on load <input type=checkbox id=sload checked> or after <input id=stime> seconds.<br>
Duration: <span id=dur></span><br>
Frame duration:
<span id=resp><br>
</div>
<div id=container>
<iframe id=frame></iframe>
</div>
<script id="jsbin-javascript">
var started;
var lastFrame;
var frames = [];
var $ = document.getElementById.bind(document);
$('url').value = "http://" + location.hash.substr(1);
function frame() {
if (!started)
return;
var now = performance.now();
frames.push(now - lastFrame);
lastFrame = now;
var max = Number($('stime').value);
if (max && now - started > max * 1000)
done();
else
requestAnimationFrame(frame);
}
$('go').addEventListener('click', function() {
$('dur').textContent = '';
$('resp').textContent = '';
started = performance.now();
lastFrame = started;
frames = [];
$('frame').src = '';
$('frame').src = $('url').value;
requestAnimationFrame(frame);
});
$('frame').addEventListener('load', function() {
if (started && $('sload').checked) {
done();
}
});
function done() {
var dur = performance.now() - started;
$('dur').textContent = Math.round(dur) + "ms " + frames.length + " frames";
started = undefined;
frames.sort(function(a,b) {
return a-b;
});
var per = [50,95,99,100];
var msg = '';
for( var i = 0; i < per.length; i++) {
var p = per[i];
var fi = Math.floor(p * frames.length / 100);
fi = Math.min(fi,frames.length-1);
var v = frames[fi];
msg += Math.round(v) + "ms@" + p + "th ";
}
$('resp').textContent = msg;
}
if (location.hash) {
$('go').click();
}
</script>
</body>
</html>