feat: improve load time calculation, show first part of ipv6 address

This commit is contained in:
Gottfried Mayer 2023-07-18 20:11:45 +00:00
parent c81daf3cb8
commit 5dacc07a1b
1 changed files with 19 additions and 9 deletions

View File

@ -6,20 +6,13 @@ function isValidIpAddr(ip) {
function truncate(ip, maxlen = 20) {
if (ip.length > maxlen) {
return '…' + ip.slice(-maxlen + 1);
return ip.slice(0, 5) + '…' + ip.slice(-maxlen + 5);
} else {
return ip;
}
}
document.addEventListener("DOMContentLoaded", async (event) => {
// display document load time
window.setTimeout(() => {
const perfData = window.performance.timing;
const loadTime = perfData.loadEventEnd - perfData.navigationStart;
document.getElementById('load').innerText = loadTime + ' ms';
}, 50);
addEventListener("DOMContentLoaded", async (event) => {
try {
const resp = await fetch('/myip');
const respText = await resp.text();
@ -37,6 +30,23 @@ document.addEventListener("DOMContentLoaded", async (event) => {
}
});
addEventListener('load', (event) => {
// display document load time
window.setTimeout(() => {
if (window && window.performance && window.performance.timing) {
const perfData = window.performance.timing;
if (perfData.loadEventEnd && perfData.navigationStart) {
const loadTime = perfData.loadEventEnd - perfData.navigationStart;
if (loadTime && loadTime > 0) {
document.getElementById('load').innerText = loadTime + ' ms';
return;
}
}
}
document.getElementById('load').innerText = 'unknown.';
}, 50);
});
/* Load Webfont */
const wof = document.createElement('link');
wof.rel = 'stylesheet';