Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular main.js file large size

My project user angular version 7, and here is the angular.json configuration enter image description here

when I build for production my main.js file is way too large nearly 12MB in size which makes my app to load the page very slowly. Nearly the initial load tooks 4 - 5 minutes

Here is the build result enter image description here

Here is my analyser result enter image description here

Thanks in advance

like image 667
VinoPravin Avatar asked Apr 23 '19 02:04

VinoPravin


People also ask

Why is Angular project size so large?

Angular is a very opinionated and robust framework. As a result, Angular apps generally have bigger bundle sizes when compared to apps written using other JavaScript frameworks like React. The Angular framework comes with a lot of useful libraries already included within it, such as RxJs and Zone.

How big should Angular bundles be?

I checked many apps built with Angular and have a feeling that most medium size enterprise apps should have main. *. js under 500 KB, on average 250KB. If your bundle size largely exceed those numbers, you may need to be aware.

What is main js file in Angular?

main. js : your application code and everything you have imported. vendor. js : third-party code that your application depends on.


2 Answers

Split the file which is taking too much into modules and apply lazy loading

like image 139
Prashanthi Avatar answered Sep 18 '22 15:09

Prashanthi


  • First of all, stop using webpack bundle analyzer because it does not give accurate representation of your bundle space and start using source-map-explorer.

  • As per the Angular docs, if you import any thing outside of lazy loaded module, then it will be included in your main.js bundle. I had this issue where I was importing shared module in every module and shared module itself imported a lot of packages from node_modules which led to an increase in main.js file.

like image 22
Aniket Sanadhya Avatar answered Sep 20 '22 15:09

Aniket Sanadhya