Created
March 26, 2020 12:51
-
-
Save andre487/cb299885ee437db0093a92696d0f034b to your computer and use it in GitHub Desktop.
Chunked page example
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
const express = require('express'); | |
const app = express(); | |
app.get('/', (req, res) => { | |
res.setHeader('Content-Type', 'text/html; charset=utf-8'); | |
res.setHeader('Transfer-Encoding', 'chunked'); | |
res.write(` | |
<!doctype html> | |
<head> | |
<title>My Page</title> | |
</head> | |
<div>First chunk</div> | |
`); | |
// Heavy query to DB simulation | |
setTimeout(() => { | |
res.end('<div>Second chunk</div>'); | |
}, 500); | |
}); | |
app.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment