It would be better to load jquery library files with Google

Source: Internet
Author: User

We recommend that you use Google's CDN-Content Delivery Network to load jquery library files on your website. Some may ask why Google's jquery library file should be loaded? (PS: do we usually load jquery library files on our servers ?). Haha ~~ As a matter of fact, I have always thought about loading jquery files on my server.

Next we will analyze the advantages of using Google to load jquery library files.

1. Reduce the waiting time
We often use the jQuery library on Web pages. You should feel the strength of jquery and the strength of the jquery team. Now jquery is available in version 1.5.1, however, even after the mini compression, the code is 83.2KB. CDN-Content Delivery Network (Content Delivery Network) refers to the distribution of some of your static Content through a variety of service channels. When a user's browser submits a request for a link to these files, they will automatically download the most recent available files on the network.
For this reason, any user using your service downloads the JQuery library from Google faster than downloading it from your own server. In fact, there are many CDN services comparable to Google's, but it is difficult for them to surpass Google's free service advantages. This benefit is enough to determine the problem, but this is only part of it.

2. Increase the Simultaneous loading speed of webpages
To avoid service overload, the browser limits the number of simultaneous connections. Depending on different browsers, this limit may be limited to only two of each data center. Use Google's AJAX content service network to respond to your website, so that more services can be performed on your local server at the same time. This is not surprising when users use six browsers at the same time, but (those who do not do so) either runs a browser, only two connections (the number of connections to your server) are allowed at the same time. The difference here is obvious.

3. Better use of Cache
The biggest benefit of using the Google AJAX library content publishing service is that your users do not need to download jQuery. no matter how powerful your cache is, if you use your server to provide jQuery, your users must download it at least once, A user may download many identical jQuery files in their browser's cache. min. but when they visit your website for the first time, these copied versions will be ignored.
On the other hand, when the browser detects a link to Google in the same version, it will know that this is the download of the same file, not only does Google's server return a 304 message (no command to modify the file, that is, the file on the server has not been changed) to reply to a duplicate request, it also commands the browser to cache the file for up to one year. This means that even if some people access hundreds of jQuery websites using Google services, they only need to download them once.

Although Google's jQuery source is quite stable, we cannot guarantee that it can be accessed at any time. Once Google servers cannot be accessed (this is unlikely), will our website suffer? So we need to give it another option to load jQuery according to the conditions and add a backup source, as shown below:

<SCRIPT type=text/javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></SCRIPT><script>!window.jQuery && document.write('<SCRIPT src="jquery-1.4.3.min.js"><\\/SCRIPT>');</script>

In addition, the selected jQuery loading source can effectively accelerate website loading. Currently, in addition to Google's Jquery source, the CDN jQuery source provided by Microsoft can also be used, combined with the Jquery source call method provided by google and Microsoft:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script><script type="text/javascript"><!--!window.jQuery && document.write('<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"><\/script>');//--><!--!window.jQuery && document.write('<script src="jquery-1.4.3.min.js"><\/script>');//--></script>

You can also write as follows:

<!--document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));!window.jQuery && document.write(unescape("%3Cscript src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js' type='text/javascript'%3E%3C/script%3E"));//-->

Then save it to jQuery. js and load it locally. The file is small, the load is fast, and the version change is very convenient.

The second address can be replaced with your local jQuery to ensure link stability. The significance is: first load Google's jquery library file. If loading fails, load Microsoft's jquery library file. If google jquery is loaded successfully, the Microsoft jQuery code is ignored.

Here are the Jquery source locations for Google and Microsoft:

Google Ajax API CDN

Http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js

Google Ajax CDN Documentation

Microsoft CDN

Http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js

Http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js

Ajax CDN Announcement, Microsoft Ajax CDN Documentation

Articles you may be interested in
  • Jquery checks whether the page has been loaded with the jquery File
  • JavaScript and Jquery dynamically load Js files and Css files
  • Php uses header () to download files. The downloaded files prompt that they are damaged and cannot be opened.
  • Use the GZip compression function of PHP to compress website JS and CSS files to accelerate Website access.
  • Detailed usage of the jQuery plug-in (Lazy Load) for delayed image loading
  • Use SecureCRT to upload and download files (using sz and rz commands)
  • Prohibit web page right-click, copy, save as, View Source file and other functions to implement web page source code protection
  • Where is the CMS database configuration file?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.