Делаю рендер html через стримы. Проблема в Safari - он не выводит кусочками, а как будто буферизирует и затем выводит всё сразу.
const { createServer } = require('node:http')
const { setTimeout: delay } = require('node:timers/promises')
createServer(requestHandler)
.listen(process.env.PORT || 3000, () => {
console.log(`Server is running on http://localhost:3000`)
})
async function requestHandler(request, response) {
const items = ['a', 'b', 'c', 'd', 'e', 'f']
response.writeHead(200, {
'content-type': 'text/html; charset=utf-8'
})
response.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stream Example</title>
</head>
<body>
`)
for await (const item of items) {
response.write(`
<div>${item}</div>
`)
await delay(1000)
}
response.end(`
</body>
</html>
`)
}
repl.it