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?
-
4Minify all javascript filesAniket Kulkarni– Aniket Kulkarni2015-01-27 13:56:30 +00:00Commented Jan 27, 2015 at 13:56
-
1Is there no other way?Arindam Barman– Arindam Barman2015-01-27 13:58:06 +00:00Commented Jan 27, 2015 at 13:58
-
1Building a single minified file is usually the best way. Your page load is slow because of aggregated network latency and the browser's parallel download limit. A single file mitigates both.joews– joews2015-01-27 14:09:24 +00:00Commented Jan 27, 2015 at 14:09
1 Answer
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.