-
Notifications
You must be signed in to change notification settings - Fork 3
Preload dynamic import chunks #151
Comments
At first I thought this would be tricky because we don't use Then I realized that we have a lot more control over the delivery of dynamic modules than other frameworks do, so I think there is definitely a way to make this work. We just can't directly borrow what other frameworks have done. I think the essence of our approach should be to send information down as part of the initial response that can prime the IndexedDB module cache, so that the modules are immediately available when/if the client imports them dynamically. To prime the cache we just need the string of code we would have fetched, along with its hash. Seems pretty straightforward, actually! In order for this technique to help, we just need to make sure the cache gets primed before any client code calls |
Basically you want to call Here’s where we currently call it (after receiving fetched dynamic modules). The |
My solution to this issue is to load the needed async component before rendering routes so that the first page of the app will look like synchronized (no flash). Here's a package I wrote react-code-split-ssr. Hope it helps |
@lhz516 can you elaborate a little on your solution how it achieves ssr? |
@sirpy It's in the README |
Is there any update? It's very interesting. |
any updates on this issue? |
I am writing vuejs app with meteor. It would be quite nice to be able to define chunks for dynamic imports, I noticed there is a solution for it in vue-cli:
I suggest to use it with just renaming |
Feature
Support including (via script tag or inline?) the bundled modules of dynamically imported before application startup occurs.
Use Case
Let's say that I have a simple react app with server side rendering:
During the server render, I have would sync access to
./my-component
resulting in the markup of that component being generated and sent alongsideHello world
to the client for viewing. While the user is distracted by the wonderful SSR'd content, I download and bootup my client side application. During that bootup, the react app does not have access to./my-component
so it returns a promise while loading it. Since react is sync in its loading, my wonderful content disappears to the user while the module is sent over DDP. After it is loaded, the app re-renders and my content is back.This flash makes the app feel broken, does more work on the client, and results in a less than ideal experience for the user.
In an ideal world, since meteor would know over the course of the server side render, which modules were accessed, it would include script tags for the
bootstrap
,modules
, thenapplication
.For an example implementation on a framework level: next
For an example in userland / config level: webpack-flush-chunks
The text was updated successfully, but these errors were encountered: