-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync-and-sync-scripts.html
83 lines (69 loc) · 2.49 KB
/
async-and-sync-scripts.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
<html>
<head>
<script type='text/javascript'>
var currentReadyState = document.readyState;
var messages = [];
messages.push('Executing top of head');
</script>
<script type='text/javascript'>
var script = document.createElement('script');
script.src = './C.js';
script.type = 'text/javascript';
script.async = true;
var head = document.head;
head.appendChild(script);
messages.push('Injected async script C near bottom of head');
script = document.createElement('script');
script.src = './D.js';
script.type = 'text/javascript';
script.async = false;
head = document.head;
head.appendChild(script);
messages.push('Injected sync script D at bottom of head');
script = document.createElement('script');
script.src = './B.js';
script.type = 'text/javascript';
script.async = false;
head = document.head;
head.insertBefore(script, head.firstChild);
messages.push('Injected sync script B near top of head');
script = document.createElement('script');
script.src = './A.js';
script.type = 'text/javascript';
script.async = true;
head = document.head;
head.insertBefore(script, head.firstChild);
messages.push('Injected async script A at top of head');
document.addEventListener('DOMContentLoaded', function recordDOMLoad() {
messages.push('DOM loaded and parsed');
});
window.addEventListener('load', function recordLoad() {
messages.push('All content loaded');
});
document.addEventListener('readystatechange', function recordDocumentReadyState() {
messages.push('Document readyState changed from "' + currentReadyState + '" to "' + document.readyState + '"');
currentReadyState = document.readyState;
});
setTimeout(function appendParagraphs() {
messages.forEach(function appendParagraph(message) {
var p = document.createElement('p');
p.textContent = message;
var body = document.body;
body.appendChild(p);
})
}, 1000);
</script>
<script type='text/javascript'>
messages.push('Executing bottom of head');
</script>
</head>
<body>
<script type='text/javascript'>
messages.push('Executing top of body');
</script>
<p>Initial body paragraph</p>
<script type='text/javascript'>
messages.push('Executing bottom of body');
</script>
</body>
</html>