Home  >  Article  >  Web Front-end  >  What is the use of cdn in jquery

What is the use of cdn in jquery

(*-*)浩
(*-*)浩Original
2019-05-30 11:07:494641browse

jQuery is the most common and popular javascript library for front-end development. How to load it to make our project perform better and why should we use CDN?

When users visit their own sites, files are loaded from the server. Each server can only download 2-4 files at the same time, which will reduce the execution efficiency of the file. If more servers are used, this will The number of files loaded at the same time is (2-4)*number of servers, So we put jQuery on the CDN to improve the efficiency of loading files on the website.

What is the use of cdn in jquery

Let’s talk about the commonly used jQuery CDN

foreign CDN:

//Google Hosted Libraries
src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
//Microsoft CDN
src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js"
//CDNJS
src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"
//jQuery官网
src="http://code.jquery.com/jquery-1.11.0.min.js"
//jsDeliver
src="http://cdn.jsdelivr.net/jquery/2.0.0/jquery-2.0.0.min.js"

Domestic CDN:

//百度
src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"
//七牛
src="http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"
//新浪
src="http://lib.sinaapp.com/js/jquery/1.6/jquery.min.js"
//又拍云
src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.0.min.js"
//360
src="http://libs.useso.com/js/jquery/2.0.0/jquery.min.js"

Summary:

Except foreign Google Except for the services of CDNJS, domestic libraries do not support the HTTPS environment. Unfortunately, it is slow to load for domestic users. If you set up your website abroad, you can give priority to using it. If the CDN fails to load, we need to load our own local jQuery file. We only need to add the following code to the header.

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.11.1.min.js" type="text/javascript"><\/script>')</script>

The above is the detailed content of What is the use of cdn in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn