Use the jquery library provided by Google CDN

Source: Internet
Author: User
Tags jquery library

Jquery makes it easier and quicker to control page elements, so we don't need to worry too much about browser features when writing JavaScript. However, the more powerful jquery is, the more files it has. During website optimization, we usually optimize the hundreds of K downloads that can be squeezed out by JS, CSS, and image files.

Google is very interesting enough to provide the jquery library. By using the jquery library provided by Google, Google's server and line quality are naturally nothing. This increases the download speed and reduces the number of concurrent connections on your server.

It's easy to use. Just 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 to the page headerCode:
<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

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.