10

I have pasted a screenshot after i run ng serve. it is on 34946 ms. it is pretty slow and it is hurting the performance of our team. When we also update our code, it takes too long to reload the page.

enter image description here

My version of angular is Angular CLI version (1.2.7)

Is this an issue or is this normal in Angular CLI?

We already have around 40 components on the project but i am not sure if it affects the loading performance.

Here is the specs of my PC just incase.

enter image description here

2
  • Do you put any argument when serving ?
    – Ploppy
    Aug 22, 2017 at 13:21
  • i am just using plain "ng serve" command on terminal Aug 22, 2017 at 13:22

3 Answers 3

9

i solved my problem. What happened is that our components and other resources are all imported in app.module.ts. Because of this, the page loads all the resources every time the page loads. My solution was to apply Lazy Loading to load only those resources that are specific to the routes that i am accessing and it did fix up the loading issue.

4
  • 6
    "My solution was to apply Lazy Loading" it is still not clear what you mean by lazy loading. If you could elaborate it, with an example. Then It would be better.
    – Aman
    May 12, 2020 at 6:52
  • 1
    @Voiltaire please comment with an example to help the community who are facing a problem right away like your's. May 23, 2020 at 7:11
  • How to apply lazy loading ? Jul 1, 2020 at 13:34
  • This is how - angular.io/guide/lazy-loading-ngmodules Aug 8, 2020 at 6:39
8

You have this problem is because your dev PC have not enough memory to handle the build as nodejs is consuming a lot of memory when you run expensive npm tasks. And the bigger your project the more memory is required to complete the task. The problem can get even worse if you want to run ng serve + ng t + ng whatewer at the same time.

Check the Task manager -> Perfomrmance tab then run ng serve and you will see what I am talking about.

I had struggled by the same problem until I put another 8gb RAM in my dev PC.

So yes it is normal.

8
  • I'm watching it and it takes only 55% of my RAM. Not enough?
    – Jeb50
    Sep 3, 2019 at 22:44
  • @Jeb50 how much RAM you've got in total? Sep 4, 2019 at 5:22
  • 8 GB, everything goes very well except ng serve takes 30 seconds to show percentage.
    – Jeb50
    Sep 4, 2019 at 21:31
  • I'm at 16GB and takes 1-2 min to recompile using --aot. Any suggestions? Nov 21, 2019 at 15:48
  • @java-addict301 how big is your project? what is your cli version? Nov 26, 2019 at 23:55
2

You Just Need to update angular cli version I hope this will solve your issue

 npm install @angular/cli@latest     

If this one Does not solve your Issue Means Just Run using this Cmd

 ng serve --sourceMap=false    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.