The jquery class library has a size of about 25 KB (minimum and gzip compression). The loading speed of the jquery class library is not ideal when the user's network speed is not ideal, we need to load jquery from the CDN network. One is to save some bandwidth, and the other is to bring users a faster page loading experience.
25kb x 100000 unique Pv = GB traffic. If a website with a higher traffic volume occupies a higher bandwidth.
According to the authoritative survey report http://royal.pingdom.com/2010/05/11/cdn-performance-downloading-jquery-from-google-microsoft-and-edgecast-cdns/ released by pingdom, the fastest CDN is edgecast, so we can call jquery of edgecast.
The following CDN is from the official jquery website. We directly use the officially recommended CDN!
- Jquery CDN (edgecast via (MT ))
- Http://code.jquery.com/jquery-1.4.2.min.js minified version
- Http://code.jquery.com/jquery-1.4.2.js source version
- PleaseDo not linkVersions of jquery onStatic.Jquery.com orDev.Jquery.com; hotlinking to these subdomains will be disabled in Q3 of 2010 and your sites will break!
- Google Ajax API CDN
- Http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
- Google Ajax CDN documentation
- Microsoft CDN
- Http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js
- Ajax CDN announcement, Microsoft Ajax CDN documentation
In addition, the Google jquery CDN method is easy to use. You can directly reference the relevant JS files on the Google server on the webpage. However, if you reference multiple JavaScript codes, you need to insert multiple scripts. Google also provides the corresponding method, that is, Google load. We only need to reference a JS file on the page to load the JS library used in real time as needed.
First, add the following line of code to the page header:
<SCRIPT type = "text/JavaScript" src = "http://www.google.com/jsapi"> </SCRIPT>
Load jquery, which can be used as follows:
Google. Load ("jquery", "1.3.2 ");
In this way, we load the JS library of jquery 1.3.2 from Google's latest CDN image, and then we can write the JS Code normally. However, even Google's CDN images take time to download. What if the browser has explained the following code before the code library is downloaded? We can set to execute JS after loading the JS Library:
Google. setonloadcallback (function () {// code to be executed });
For more information about Google jsapi, see: Google Ajax library API
In addition to jquery, Google also provides APIs for the following JS frameworks/Libraries:
Jquery UI
Prototype
Script. aculo. Us
Mootools