Arindam Barman
Arindam Barman

Reputation: 107

What is the best way to load javascript scripts with Angularjs?

I have a lot of external scripts to be used for angularjs and so the intial page load becomes slow. Though I need some scripts only for some views. I'm using ui-router. What is the best way to make the inital page load fast?

Upvotes: 0

Views: 93

Answers (1)

Roman Bekkiev
Roman Bekkiev

Reputation: 3118

In modern Internet the size of your script is not actually matters (if it is not several megabytes). Say your script is 500kb minified and gziped (it is really BIG script), say your bandwidth is 10 mbps so your script will be downloaded about 0.4s. It is about that long as DNS lookup + latency will take too. Script loads ones and then it'll be cached. And if you are using Angular I can assume that you're building SPA, so user wants to see all "inner pages" will loads instantly. There is no actual reason to slow its down. And finally, using lazzy loaded angular modules is a tricky thing. So the best choice is to concatenate and minify all js on server side.

Upvotes: 1

Related Questions