Best practice for assets in Angular

Viewed 513

When would assets get loaded in Angular app? Will app wait for all assets to be loaded before starting to bootstrap, or those will be lazy loaded if they are not required on initial page.

I have a lot of PDFs that I put in assets folder and load them when required. Now, I am concern about the performance, and I was thinking to upload all PDFs to cloud and instead of loading them from assets I would load them from cloud. Would that make app initial load faster?

1 Answers

Files in assets gets loaded as and when they are requested by the components.

They won't be bundled in to the output JS files produced by the Angular build process. So your bundle size will not be impacted by the number of files you have put in to the assets folder.

If you are concerned to make the app's initial load faster, make sure that your you are splitting your code in different bundles and the main bundle only contains the components required for initial page load.

You can implement lazy loaded modules to split your application code.

Related