-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemplate.html
171 lines (157 loc) · 6.16 KB
/
template.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preload" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.119.woff2" as="font" crossorigin="anonymous"/>
<link rel="preload" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.118.woff2" as="font" crossorigin="anonymous"/>
<link rel="preload" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.116.woff2" as="font" crossorigin="anonymous"/>
<!-- <link rel="prefetch" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.113.woff2" as="font"/>
<link rel="prefetch" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.118.woff2" as="font"/>
<link rel="prefetch" href="https://fonts.gstatic.com/s/longcang/v5/LYjAdGP8kkgoTec8zkRgqHAtXN-dRp6ohF_hzzTtOcBgYoCKmPpHHEBiM6LIGv3EnKLjtw.117.woff2" as="font"/>
-->
<!-- <link rel="dns-prefetch" href="https://ss1.bdstatic.com" />
<link rel="dns-prefetch" href="https://ss0.bdstatic.com" />
<link rel="dns-prefetch" href="https://timgsa.baidu.com" />
<link rel="dns-prefetch" href="https://ss2.bdstatic.com" /> -->
<!--引入工具库-->
<style>
body {
margin: 0;
}
#loadding {
position: fixed;
top: 0;
bottom: 0;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
#loadding > span {
display: inline-block;
width: 8px;
height: 100%;
margin-right: 5px;
border-radius: 4px;
-webkit-animation: load 1.04s ease infinite;
animation: load 1.04s ease infinite;
}
@keyframes load {
0%,100%{
height: 40px;
background: #98BEFF;
}
50%{
height: 60px;
margin-top: -20px;
background: #3E7FEE;
}
}
</style>
<title>前端性能优化</title>
</head>
<body>
<!-- <img src="./img/index.jpg" sizes="100vw" srcset="./img/me0.jpg 300w, ./img/dog.jpg 800w, ./img/index.jpg 1200w"/> -->
<div id="loadding">
<span></span>
<span style="animation-delay:0.13s;"></span>
<span style="animation-delay:0.26s;"></span>
<span style="animation-delay:0.39s;"></span>
<span style="animation-delay:0.52s;"></span>
</div>
<div id="main">
</div>
<!-- <script src="/libs/lodash.js"></script> -->
<script src="/libs/fastdom.min.js"></script>
</body>
<script>
window.addEventListener('DOMContentLoaded', () => {
const $loadding = document.getElementById('loadding');
if (!$loadding) {
return;
}
$loadding.style.display = 'none';
$loadding.parentNode.removeChild($loadding);
});
// 连续触发页面回流操作
// let cards = document.getElementsByTagName("img");
// const update = (timestamp) => {
// for (let i = 0; i <cards.length; i++) {
// let top = cards[i].offsetTop;
// cards[i].style.width = ((Math.sin(cards[i].offsetTop + timestamp / 100 + 1) * 500) + 'px')
// }
// window.requestAnimationFrame(update)
// }
// // const update = (timestamp) => {
// // for (let i = 0; i < cards.length; i++) {
// // fastdom.measure(() => {
// // let top = cards[i].offsetTop;
// // fastdom.mutate(() => {
// // cards[i].style.width =
// // Math.sin(top + timestamp / 100 + 1) * 500 + "px";
// // });
// // });
// // }
// // window.requestAnimationFrame(update);
// // };
// update(1000);
// rAF 处理一些高频事件
// let cards = document.getElementsByTagName("img");
// const changeWidth = (pos) => {
// for (let i = 0; i <cards.length; i++) {
// cards[i].style.width = ((Math.sin(pos/100) * 500) + 'px')
// }
// }
// let ticking = false;
// window.addEventListener("pointermove", (e) => {
// let pos = e.clientX;
// // if(ticking) return;
// // ticking = true;
// // window.requestAnimationFrame(() => {
// // changeWidth(pos);
// // ticking = false;
// // })
// // changeWidth(pos)
// })
let vEvent = "visibilitychange";
if (document.webkitHidden != undefined) {
vEvent = "webkitvisibilitychange";
}
function visibilityChanged() {
if (document.hidden || document.webkitHidden) {
document.title = "客官,别走啊~";
console.log("Web page is hidden.");
} else {
document.title = "客官,你又回来了呢~";
console.log("Web page is visible.");
}
}
// document.addEventListener(vEvent, visibilityChanged, false);
// 观察长任务
// const observer = new PerformanceObserver((list) => {
// for (const entry of list.getEntries()) {
// console.log(entry)
// }
// })
// observer.observe({entryTypes: ['longtask']})
// 计算DOMContentLoaded时间
// window.addEventListener('DOMContentLoaded', (event) => {
// // Time to Interactive
// let timing = performance.getEntriesByType('navigation')[0];
// console.log(timing.domInteractive);
// console.log(timing.fetchStart);
// let diff = timing.domInteractive - timing.fetchStart;
// console.log("TTI: " + diff);
// })
// 监听网络变化
// var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
// var type = connection.effectiveType;
// function updateConnectionStatus() {
// console.log("Connection type changed from " + type + " to " + connection.effectiveType);
// type = connection.effectiveType;
// }
// connection.addEventListener('change', updateConnectionStatus);
</script>
</html>