What is the best way to fetch a dynamic module programmatically?

Hello, our app is using dynamic imports but we are also supporting a full offline experience.

Then when the user is in the browser (we also have Cordova App but in this case the dynamic modules are already available) we need to fetch dynamic modules before the user needs the module because if the user goes offline the module needs to be ready on the client (and we really need dynamic modules to reduce the first loading time).

In short: we need to prefetch dynamic modules programmatically 10 seconds after the first loading.

What is the best way to fetch a dynamic module programmatically? Is there a function exported from the dynamic-import package for that?

Thanks :slight_smile:

cc @nachocodoner @benjamn


Not long ago, @captainn implemented something like this in conjunction with the old appcache package (which still works amazingly well in Meteor, since we make such limited use of it): https://github.com/meteor/meteor/pull/9482

Right now the preloading only happens if Package.appcache is defined, but I think we could generalize that condition.


Thank you for the references :slight_smile: I’ll reply here when it’s done.

I also have a react-loadable fork, which uses a provider to make sure modules are loaded before hydration. I’m actually not certain that’s coordinating as well as it could with appcache’s preloader (that’s worth checking in to) - but it does work when it’s all set up correctly.