Google CDN for Angular dependencies?

Is there a way to reduce the following: to one?

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-animate.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-cookies.min.js"></script> 

I can not find a combined version of these hosted on Google CDN.

+48
javascript angularjs
Apr 22 '14 at 22:29
source share
4 answers

I searched for the bunch myself, but have not yet found it. I think you need to link them manually if you want them all to be in the same js. file.




I was thinking of creating a grunt task (or similar) to extract all the dependencies and merge them into a single file. I know that you want to use CDN, but just wanted to share this thought.

Update
For anyone interested in the latter, just stumbled upon this plugin grunt-fetch-from-cdn . I have not tried it yet, but it looks interesting.

+14
Apr 22 '14 at 22:41
source share

I would say that the main advantage of CDN is that everyone can use the same files, thereby allowing caching to remove the need to download a file in general for most visitors due to its widespread use on other sites.

Presumably, the number of permutations needed to combine the various Angular dependency configurations would completely negate this advantage, and you would be better off packing the package with all of your other JS for as few requests as possible and serving it yourself.

However, it seems that Angular is updated quite often, which, although useful for fixing bugs, means that at the moment there are many different versions (and therefore files) used in production environments. It will also reduce the benefits of caching across sites.

If in doubt, check both methods on different devices with friends / family / work / etc. who have seen the normal use of the Internet on sites other than your own.

I would suggest that in most cases it would be wiser to simply include each link of the CDN module separately, as you did above, and let caching take care of reducing the actual number of requests. If this becomes common practice, then the additional number of files will not have much impact on the download time.

+7
Oct 14 '14 at 2:43 on
source share

I agree with Colt, but the following may be useful if you use it wisely (see "Uploading Multiple Files with a Single HTTP Request"): JSDelivr

+2
Jan 16 '15 at 22:08
source share

Either you can use the gulp task to create them in one script, or you can use the conversation to install these dependencies right away.

+2
Dec 03 '15 at 7:25
source share



All Articles