Reputation: 759
Ever since upgrading my Angular app to version 5, then version 6, it's been downloading very slowly in the browser, sometimes taking well over 30 or 40 seconds. Though I'm optimizing the build for production, (ng build --prod --build-optimizer --aot
), the core files add up to over a megabyte.
The main offenders are
main.1acde84f0c61a49d6387.js
, which is 831kb, styles.99d75733e80daf42e5f9.css
, which is 269kb, and 0.06cf948c35f50dabe8dc.js
, which is 243kb.Are these files typically so large? Any idea how I can trim them down and improve download speed?
Upvotes: 2
Views: 4047
Reputation: 297
The reason is you bundle all your application inside one module.
It means all your pages,components,... will bundle in one file, it surely will be heavy.
The solution here is you should separate your application to more smaller bundles. In Angular
it called is module lazy load
and implement preloading
(optional) to decrease bundle size
at first time loading.
You can follow these articles:
Or follow these steps:
Use loadChildren
to load this module at app router
. Something like that:
{ path: 'a', loadChildren: './anynomous/anynomous.module#AnynomousModule' },
Upvotes: 4