Why should I use Google's CDN for jQuery?

后端 未结 7 1540
长发绾君心
长发绾君心 2020-11-22 06:21

This may be obvious to some, but I\'ve been wondering: why should I depend on Google\'s server to host jQuery for my site?

Is it only because it loads faster this wa

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 06:48

    There are several scenarios when you might not want to use jQuery from Google's CDN:

    1. When you are building an intranet application where the web server is hosted on the same network as the clients. If you use Google's CDN jQuery, you will be making a call to the internet rather than a webserver on the local network. This increases bandwidth for your organization, and is slower.

    2. When you want to run your application offline. (Quite linked to the first issue) If you need to work on a development environment (managed for example with Bower), you might need to be able to make your application work without any internet connection (ie: in a train :)

    3. When you need to customize it. For example if you use Grunt to build the library in order to use only certain modules or setting the AMD name

    4. When you are serving pages over SSL that require jQuery. You should serve the JavaScript over SSL as well as your page to avoid security problems and warnings.

    Also, Microsoft hosts jQuery on their CDN. That is another choice comparable to using Google's hosted jQuery.

提交回复
热议问题