Home > Web Front-end > JS Tutorial > body text

Detailed description and implementation code of the best way to load the jQuery library_jquery

WBOY
Release: 2016-05-16 17:44:59
Original
1108 people have browsed it

Due to the current instability of Google and the lack of good similar services in China, this is no longer the optimal solution. Of course, if you change the Google library path to a domestic stable and fast path (if it exists), you can still benefit from the various benefits brought by this method. Even so, all things considered, Google is still the most suitable.

Although the jQuery library of Google CDN is used in website development projects to load very quickly, only calling the library of the local server can ensure that it is foolproof. If you use WordPress's built-in jQuery library, the jQuery.noConflict() added at the end to prevent JS library conflicts will make all jQuery codes in the theme need to be slightly modified, which may also cause some plug-in effects to fail. I think the method used by Paul Irish in HTML5 Boilerplate is very good and I would like to 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 the code The code is as follows:




The method used in WordPress themes is:
Copy code The code is as follows:




Notes
Because of the reasons mentioned at the beginning, it is recommended to download a jQuery official Min library and put it in the theme directory currently used by WordPress. Do not use wp. -Libraries in included.

The address of the Google CDN library uses a protocol relative path, which can effectively solve some problems caused by https. For details, please see Paul Irish's introduction. Of course, you can still use the path with "http:".
Many websites use the jQuery library provided by Google CDN, which can achieve excellent caching effects.
Putting all the jQuery code at the bottom of the page can improve the loading speed.
Pages reconstructed using HTML5 can omit type="text/javascript".

Use SAE developer resources
Due to recent problems with Google services, for the sake of safety, using SAE developer resources is a good way to save traffic and increase speed. SAE is a developer resource provided by Sina for its applications, including the jQuery library. It is very simple to use. Just go to the SAE Developer Center to find the appropriate address and replace the Google CDN address in the above code. For example:
Copy code The code is as follows:



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!