简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM