Skip to content

Instantly share code, notes, and snippets.

@PandiyanCool
Created January 23, 2021 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PandiyanCool/03e1eb6a4a5b250ea1eed213642ec266 to your computer and use it in GitHub Desktop.
Save PandiyanCool/03e1eb6a4a5b250ea1eed213642ec266 to your computer and use it in GitHub Desktop.
@Injectable({
providedIn: 'root'
})
export class CustomPreload implements PreloadingStrategy {
preload(route: Route, load: (): Observable<any>): Observable<any> {
// you implement this function somewhere, somehow
if (isActiveCardRoute(route)) {
// this will make it load immediately
return load();
} else {
/*
* this will load the remaining modules after 5 seconds. You can possibly make a more
* 'complex' logic to have it load sequentially or in bigger intervals to make sure
* the app doesn't lag when loading
*/
return timer(5000).pipe(
switchMap(() => load())
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment