Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check or prove that a module in angular2 is lazy loaded?

If I have access to an angular2 application's code and there is a module that is supposedly lazy loaded, is there a way, independent of examining the code, that I can test that module to see if it is lazy loaded. If necessary and there is no other way, I could add code into the module in question to test, if that is a possibility. But what code would I add?

like image 843
Reid Avatar asked Feb 25 '17 17:02

Reid


1 Answers

Background Concept: First of all, one thing needs to be clear about lazy loading. When you lazy load, it basically loads your module lazily in Memory (RAM) not from network or server. Module (js script) already present in Browser cache (HD) - got from network during app loading. Thus by lazily loading particular module helps in memory optimization, not network optimization.

How to check: Just put a console.log in constructor function of the module class definition

import { NgModule } from '@angular/core';

import { LazyComponent } from './lazy.component';
import { LazyService } from './lazy.service';

@NgModule({
  imports: [ ],
  declarations: [ LazyComponent ],
  providers: [LazyService]
})

export class LazyModule {
  constructor() {
    console.log('Lazily Loaded : LazyModule');
  }
}
like image 186
Md Kamrul Hasan Pulok Avatar answered Oct 20 '22 01:10

Md Kamrul Hasan Pulok