如何检查使用 Chrome 开发工具打开的模块的 js 文件是否延迟加载?
According to Angular's Lazy Loading guide :
You can check to see that a module is indeed being lazy loaded with the Chrome developer tools. In Chrome, open the dev tools by pressing Cmd+Option+i on a Mac or Ctrl+Alt+i on a PC and go to the Network Tab.
Once you make an action that loads a module lazily, you should be able to see a Chunk getting loaded in the Network Tab. Something like this:
NOTE: Another important check is to make sure that a module loaded lazily is not loaded again. To confirm, move to a different route and then click on the Action again, and this time it won't make a network call to load the chunk since it has already been loaded.
besides the other answers which is correct, you can use Augury tool to determine which module and component loaded lazily, Angular Augury is A Chrome and Firefox Dev Tools extension for debugging Angular applications.
Augury also helps Angular developers visualize the application through component trees, and visual debugging tools. Developers get immediate insight into their application structure, change detection and performance characteristics.
There are many ways to check this out.
After ng serve, chunk of modules (for which lazy-loading is applied) will be display in terminal. image showing chunk of file
Angular augury under Router Tree, it will show ([lazy]) for the lazy loaded modules. But make sure you have not imported that modules in app.module.ts or imported independent module unnecessarily, because it will load those file (read point 3)
In web developer tools look for file/component (for which lazy-loading is applied). If the file is present even before loading of the module then lazy loading is not working (component shouldn't be visible before module is loaded). The same file will be shown after that module has been loaded.
let's say project contain one modules -> abc.module.ts abc.module.ts contains two component abc1.component.ts and abc2.component.ts If lazy loading is working then abc1 and abc2 shouldn't be shown in the search result on searching files in web developer tools (before loading of abc module). After loading of abc module, if you again search it should be shown.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.