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?
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.
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.
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.
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.
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: -
Without a common chunk: -
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With