Skip to content

Instantly share code, notes, and snippets.

View albertstill's full-sized avatar

Albert Still albertstill

View GitHub Profile
@albertstill
albertstill / node_pipe_example.js
Last active March 6, 2018 00:59
Node streaming html example. Theory is that the assets can be loaded in the browser while the Node server fetches data to render the body.
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
/*
below is cool because the browser could download assets while we fetch data,
BUT there is a huge web breaking caveat, it seems we have to know the HTTP response code at this
moment in time. But we don't - what if there is a 500 during fetching? what happens if we actually need to 404?
Defaulting to 200 would lead to undesirable outcomes, especially with web scrapers and APM tooling.