Is it possible to preload lazy loaded modules?


#1

We have a project with AoT, lazy-loading and NS 3.0. We are now trying to improve the performance.We are having UI delays when we load the ‘lazy-module’ for the first time.

Is there a way to preload the lazy-modules while user is navigating a page? We’d like to remove these moments in which the App seems to be frozen.

Related SO question: http://stackoverflow.com/questions/42611757/how-to-preload-lazy-loaded-modules-in-nativescript


#2

Yes, in app.module.ts you can add this to @NgModule's imports to preload all modules in the background:

    NativeScriptRouterModule.forRoot(ROUTES,
        {preloadingStrategy: PreloadAllModules} // import { PreloadAllModules } from "@angular/router";
    )

#3

It works! Thank you very much