diff --git a/README.md b/README.md index bac5c16..debfe15 100644 --- a/README.md +++ b/README.md @@ -172,14 +172,7 @@ app.get('*', (req, res) => { renderer.renderToString(context, (error, html) => { if (error) return res.send(error.stack) const { - title, - htmlAttrs, - bodyAttrs, - link, - style, - script, - noscript, - meta + title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta } = context.meta.inject() return res.send(` @@ -212,34 +205,25 @@ A little more complex, but well worth it, is to instead stream your response. `v app.get('*', (req, res) => { const context = { url: req.url } const renderStream = renderer.renderToStream(context) - let firstChunk = true + renderStream.once('data', () => { + const { + title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta + } = context.meta.inject() + res.write(` + + + + ${meta.text()} + ${title.text()} + ${link.text()} + ${style.text()} + ${script.text()} + ${noscript.text()} + + + `) + }) renderStream.on('data', (chunk) => { - if (firstChunk) { - firstChunk = false - const { - title, - htmlAttrs, - bodyAttrs, - link, - style, - script, - noscript, - meta - } = context.meta.inject() - res.write(` - - - - ${meta.text()} - ${title.text()} - ${link.text()} - ${style.text()} - ${script.text()} - ${noscript.text()} - - - `) - } res.write(chunk) }) renderStream.on('end', () => {