-
-
Notifications
You must be signed in to change notification settings - Fork 388
Open
Open
Pass in a set of predefined chunk keys to enable streaming preload for known components#1015
Description
Feature Proposal
Enable streaming preloads for known components in a dynamic server rendering approach, by passing in a set of predefined chunk names to the ChunkExtractor.
Motivation
At my company we use a templating approach, where the template informs the app what components should be rendered.
Since we know ahead of render what is going to be included, we want to be able to provide that set of chunk names to ChunkExtractor, so that we can ask ChunkExtractor to generate the preload links for that set, server side with streaming enabled.
Example
${linkTags}`
// Stream the head, ahead of the body so the preloads can start downloading
stream.send(head)
const body = chunkExtractor.collectChunks( )
// you'd then pipe the stream into the response object until it's done
// This takes a while with SSR data fetching etc, so the preloads will help things run in parallel a bit more
renderToNodeStream(body).pipe(stream, { end: false })
// and finalize the response with closing HTML
stream.on('end', () =>
res.end(`${chunkExtractor.getScriptTags()}