Reprinted: Use the Google Ajax libraries API to accelerate loading of your JS scripts

Source: Internet
Author: User
ArticleDirectory
    • Ajax libraries API call Method 1:
    • Ajax libraries API call Method 2:

I originally wanted to introduce this Google Ajax library. I found this article on the Internet and wrote a lot better than me. Let's go here and hope it will be useful to everyone.

Use the Google Ajax libraries API to accelerate loading of your JS scripts

Link: http://xuming.net/2008/05/ajax-libraries-api.html

Google's tentacles seem to be ubiquitous. We can see him in every corner of the Internet.

Google has spent a lot of time making network applications faster. Calling JS scripts is one of the features that we often use. Too many script calls often slows down web pages.

Google seems to be trying to solve this problem, making it faster and easier for everyone to use the Javascript framework. To this end, Google has provided a new item called Ajax libraries API.

The idea of Ajax libraries API is very simple: it runs JavaScript on Google servers and uses Google's quick distribution server to compress gzip when necessary. More importantly, the cache mechanism is used to improve the loading of multiple users at the same time.

Using ajax libraries APIs has the following advantages:

    • Developers do not need to consider how to set the cache mechanism. Google will prepare everything for you.
    • If another applicationProgramWhen the same JavaScript framework is used, the client no longer needs to obtain the script repeatedly because it has been cached in the user's machine.
    • You do not need to consider the network environment and traffic restrictions

The Ajax libraries API currently supports the following JS frameworks:

    • Jquery
    • Prototype
    • Script. aculo. Us
    • Mootools
    • Dojo

If this cache mechanism can be applied on a large scale, it will be extremely powerful. However, in the current situation in China, we are always worried about the call speed.

Ajax libraries API call Method 1:

For example, load prototype 1.6.0.2.

<SCRIPT src = "http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"> </SCRIPT>

Ajax libraries API call Method 2:

Use Google Ajax API loader's Google. Load () method.

<SCRIPT src = "http://www.google.com/jsapi"> </SCRIPT>
<SCRIPT>
// Load jquery
Google. Load ("jquery", "1 ");
// On page load complete, fire off a jquery JSON-P Query
// Against Google Web Search
Google. setonloadcallback (function (){
$. Getjson ("http://ajax.googleapis.com/ajax/services/search/web? Q = Google &; V = 1.0 &; callback =? ",
// On search completion, process the results
Function (data ){
If (data. responsedate. RESULTS &&
Data. responsedate. Results. length> 0 ){
Renderresults (data. responsedate. Results );
}
});
});
</SCRIPT>

For details about the call method, see the relevant documentation.

Related Article

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.