Last active
September 2, 2025 15:08
-
-
Save lovasoa/5b32bbff540412fbf73140e1a92d60ed to your computer and use it in GitHub Desktop.
A script to measure when the countdown starts for meta http-equiv="refresh" in various browsers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from "http"; | |
import { URL } from "url"; | |
const port = process.env.PORT || 8000; | |
let lastInitialRequestStart = process.hrtime.bigint(); | |
function relMs() { | |
return Number(process.hrtime.bigint() - lastInitialRequestStart) / 1e6; | |
} | |
function serverLog(req, msg) { | |
console.log(`[SERVER] ${req.method} ${req.url} +${relMs().toFixed(0)}ms - ${msg}`); | |
} | |
const server = http.createServer(async (req, res) => { | |
const url = new URL(req.url, `http://${req.headers.host}`); | |
if (url.pathname === "/") { | |
lastInitialRequestStart = process.hrtime.bigint(); | |
} | |
serverLog(req, "request received"); | |
// Handle /log endpoint | |
if (url.pathname === "/log") { | |
const event = url.searchParams.get("event") || "unknown"; | |
const ts = url.searchParams.get("ts") || ""; | |
console.log(`[CLIENT EVENT] +${relMs().toFixed(0)}ms ${event} at ${ts}ms`); | |
res.writeHead(204); | |
return res.end(); | |
} | |
// Handle /redirected endpoint | |
if (url.pathname === "/redirected") { | |
res.writeHead(200, { "Content-Type": "text/html" }); | |
res.end("<html><body><h1>Redirected!</h1></body></html>"); | |
const sinceInitial = Number(process.hrtime.bigint() - lastInitialRequestStart) / 1e6; | |
console.log( | |
`[SERVER] ${req.method} ${req.url} +0ms - redirected request received (${sinceInitial.toFixed(0)}ms since initial request)` | |
); | |
return; | |
} | |
// Serve main test page | |
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); | |
// 1. Send initial head with meta refresh | |
const htmlHead = `<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="refresh" content="5;url=/redirected"> | |
<title>Meta Refresh Timing Test</title> | |
<script> | |
const start = performance.now(); | |
function logEvent(name) { | |
fetch(\`/log?event=\${name}&ts=\${Math.round(performance.now() - start)}\`); | |
} | |
logEvent('script-loaded'); | |
document.addEventListener('DOMContentLoaded', () => logEvent('DOMContentLoaded')); | |
window.addEventListener('load', () => logEvent('window-load')); | |
</script> | |
</head> | |
<body> | |
<h1>Testing Meta Refresh Timing</h1> | |
<p>Meta refresh set to 5s. Streaming content slowly...</p> | |
`; | |
res.write(htmlHead); | |
await new Promise(r => setTimeout(r, 2000)); | |
// 2. Send partial body | |
res.write("<p>Chunk 1 sent after 2s...</p>\n"); | |
await new Promise(r => setTimeout(r, 2000)); | |
// 3. Send another body chunk | |
res.write("<p>Chunk 2 sent after 4s, with large image: <img src='https://placehold.co/4000x4000' alt='Placeholder'></p>\n"); | |
await new Promise(r => setTimeout(r, 5000)); | |
// 4. Send final body | |
res.end("<p>Final chunk sent after 9s. End of page.</p></body></html>"); | |
}); | |
server.listen(port, () => { | |
console.log(`Serving on http://localhost:${port} ...`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SERVER] GET / +0ms - request received | |
[SERVER] GET /.well-known/appspecific/com.chrome.devtools.json +13ms - request received | |
[SERVER] GET /log?event=script-loaded&ts=0 +16ms - request received | |
[CLIENT EVENT] +17ms script-loaded at 0ms | |
[SERVER] GET /log?event=DOMContentLoaded&ts=8996 +9011ms - request received | |
[CLIENT EVENT] +9011ms DOMContentLoaded at 8996ms | |
[SERVER] GET /log?event=window-load&ts=8996 +9013ms - request received | |
[CLIENT EVENT] +9013ms window-load at 8996ms | |
[SERVER] GET /favicon.ico +9014ms - request received | |
[SERVER] GET /redirected +14015ms - request received | |
[SERVER] GET /redirected +0ms - redirected request received (14016ms since initial request) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SERVER] GET / +0ms - request received | |
[SERVER] GET /log?event=script-loaded&ts=0 +74ms - request received | |
[CLIENT EVENT] +75ms script-loaded at 0ms | |
[SERVER] GET /favicon.ico +1286ms - request received | |
[SERVER] GET /log?event=DOMContentLoaded&ts=8994 +9020ms - request received | |
[CLIENT EVENT] +9020ms DOMContentLoaded at 8994ms | |
[SERVER] GET /log?event=window-load&ts=8997 +9022ms - request received | |
[CLIENT EVENT] +9022ms window-load at 8997ms | |
[SERVER] GET /redirected +14063ms - request received | |
[SERVER] GET /redirected +0ms - redirected request received (14064ms since initial request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment