Detailed description and implementation code of the best method for loading the jQuery Library

Source: Internet
Author: User
Tags html5 boilerplate

Because Google is currently unstable and there is no similar service in China, it is no longer the best solution. Of course, you can still use this method to change the Google library path to a stable and fast path in China (if any. Even so, Google is the best choice for comprehensive consideration.

Although Google CDN's jQuery library is quickly loaded in website development projects, it is safe to call the local server library. If you use the Wordpress built-in jQuery library, the end of the jQuery library is added to prevent JS library conflicts. noConflict () makes some minor modifications to all jQuery code in the topic, which may render some plug-ins ineffective. I think the method Paul Irish uses in HTML5 Boilerplate is very good and I will share it with you.

Usage
Use the following code to load the local jQuery library when the Google CDN library fails to be obtained:Copy codeThe Code is as follows: <script type = "text/javascript" src = "// ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"> </script>
<Script type = "text/javascript"> window. jQuery | document. write ('<script type = "text/javascript" src = "/js/libs/jquery. min. js "> \ x3C/script> ') </script>

The method used in the Wordpress topic is:Copy codeThe Code is as follows: <script type = "text/javascript" src = "// ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"> </script>
<Script type = "text/javascript"> window. jQuery | document. write ('<script type = "text/javascript" src = "<? Php echo get_template_directory_uri ();?> /Jquery. min. js "> \ x3C/script> ') </script>

Notes
We recommend that you download the official jQuery Min library and put it in the topic directory currently used by Wordpress. Do not use the library in wp-DES.

The address of the Google CDN library uses the protocol relative path, which can solve some problems caused by https. For details, refer to Paul Irish's introduction. Of course, you can still use the "http:.
Many websites use the jQuery library provided by Google CDN to achieve excellent cache performance.
Placing all jQuery code at the bottom of the page can increase the loading speed.
You can omit type = "text/javascript" for pages reconstructed using HTML5 ".

Use SAE developer Resources
Due to some recent problems with Google services, it is a good way to use SAES developer resources to increase the traffic speed. SAE is the developer resource provided by Sina for its applications, where there is a jQuery library. It is very easy to use, as long as you find the appropriate address in the SAE Developer Center and replace the Google CDN address of the above Code. For example:Copy codeThe Code is as follows: <script type = "text/javascript" src = "// lib.sinaapp.com/js/jquery/1.5.2/jquery.min.js"> </script>
<Script type = "text/javascript"> window. jQuery | document. write ('<script type = "text/javascript" src = "/js/libs/jquery. min. js "> \ x3C/script> ') </script>

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.