Skip to content

Instantly share code, notes, and snippets.

@andre487
Created March 26, 2020 12:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andre487/cb299885ee437db0093a92696d0f034b to your computer and use it in GitHub Desktop.
Save andre487/cb299885ee437db0093a92696d0f034b to your computer and use it in GitHub Desktop.
Chunked page example
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