Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Lazyload routes generates extra chunk files with prefix default~pages

I'm trying to implement lazy loading routes for the project I'm currently working on. everything works and I get no errors, I can also see when I go to new pages new chunk files load.

however, in addition to my expected chunk files, cli also creates few extra files with prefix "default~pages", such as

default~pages-managers--managers-module~pages-hosts-hosts-module~pa~0e1f5bc0

and these files with default~ prefix load regardless of what page I'm landing on. For example, if I'm on the home page, I see both:

pages-home-home-module

and

default~pages-managers--managers-module~pages-hosts-hosts-module~pa~0e1f5bc0

does anyone know what are these default files are and how to get rid of them?

like image 817
pouya zad Avatar asked May 02 '19 00:05

pouya zad


People also ask

What is Lazyload in Angular?

Lazy loading is a technique in Angular that allows you to load JavaScript components asynchronously when a specific route is activated. It improves the speed of the application load time by splitting the application into several bundles. When the user navigates through the app, the bundles are loaded as required.

What is lazy loading in angular8?

Lazy loading is the process of loading some features of your Angular application only when you navigate to their routes for the first time. This can be useful for increasing your app performance and decreasing the initial size of the bundle transmitted to the user's browser.

What is lazy loading and eager loading in Angular?

Eager Loading: used to load core modules and feature modules that are required to start the application. Pre-Loading: used to load specific feature modules that are very likely to be used soon after the application started. Lazy Loading: all other modules could be lazily loaded on demand after the application started.

How is lazy loading achieved when is it useful what are its pitfalls?

One form of lazy loading is infinity scroll, in which, the content of the web page is loaded as and when the user scrolls down the page. It is a popular technique being used by various websites. Advantages of Lazy loading: On-demand loading reduces time consumption and memory usage thereby optimizing content delivery.


2 Answers

This comment is w.r.t. Angular version 11.2.1...

This is a default feature (set to true) that could be configured in angular.json file (Andre Elrico has already answered it), but I see a great benefit of keeping this default (i.e. bundle size(s) to load on the Network and build times). Below is a demonstration: -

With a common chunk: - enter image description here

Without a common chunk: - enter image description here

Outro: I can say- with the 2nd approach, common modules will get merged with each individual lazy-loaded module. If that is what you are looking for; then tweak the settings in angular.json file.

Please Note: The build time is dependant on the Operating System, Hardware Config, etc.

like image 65
Santhosh John Avatar answered Sep 20 '22 11:09

Santhosh John


Hope this helps:

I had the same issue that commonChunks with default~ .... where generated.

use in your angular.json (where you have "aot": true ... etc.):

"commonChunk": false

like image 31
Andre Elrico Avatar answered Sep 16 '22 11:09

Andre Elrico