You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
import{ChunkExtractor}from'@loadable/server'// This is the stats file generated by webpack loadable pluginconststatsFile=path.resolve('../dist/loadable-stats.json')// We'd fetch the template server side before rendering the app and extract the component keysconsttemplateKeys=['key1','key2', ...]// We create an extractor from the statsFile and pass in the known component chunk namesconstextractor=newChunkExtractor({ statsFile,predefinedChunkNames: templateKeys})// Get the preload links for the known components constlinkTags=extractor.getPredefinedLinkTags()conststream=SomeSteamconsthead=`<html><head>${linkTags}</head><body>`// Stream the head, ahead of the body so the preloads can start downloadingstream.send(head)constbody=chunkExtractor.collectChunks(<YourApp/>)// 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 morerenderToNodeStream(body).pipe(stream,{end: false})// and finalize the response with closing HTMLstream.on('end',()=>res.end(`${chunkExtractor.getScriptTags()}</body></html>`),)
Pitch
Unlocks more complex rendering approaches to use preloading, that mix static/known and dynamic components.
The text was updated successfully, but these errors were encountered:
I realised we might actually be able to do this without needing to change anything, we can getScriptElements before calling collectChunks and then filter that set by the keys?
🚀 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 askChunkExtractor
to generate the preload links for that set, server side with streaming enabled.Example
Pitch
Unlocks more complex rendering approaches to use preloading, that mix static/known and dynamic components.
The text was updated successfully, but these errors were encountered: