Next.js Discord

Discord Forum

Use Lazy Loading for Code Splitting without an extra round-trip?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Avatar
Sun bearOP
I was wondering if it's possible to use the Next dynamic loader to basically create multiple client bundles which would all be sent on initial page load but contain different portions of the clientside app.

The use case is that in cases where I have a Client Component that is part of a feature only some users should receive, I want only those users to have to download the code for it. I can use dynamic for this, since it only loads the code when the lazy-loaded component is actually rendered, but it seems to send the request to obtain the component code after the page has already been returned to the client, requiring another roundtrip. Instead, I would like for all relevant bundles to be shipped upfront but as separate files so that the end-user receives only the code they want.

0 Replies