Website optimization: Reference CDN Public JS Library

Source: Internet
Author: User
Tags jquery library

What is a CDN public library?

CDN Public Library refers to the common JS inventory placed in the CDN node, in order to facilitate the broad masses of developers directly call. Compared with the JS inventory on the server machine, the CDN Public Library is more stable and high-speed. The General CDN Public Library will contain all the most popular open source JavaScript libraries in the world.

Why refer to CDN Public library?

1. Reduce waiting time

Cdn-content Delivery Network, a variety of service channels to separate some of your static content, when the user's browser submits the link request for these files, they will automatically download the latest available files on the network. So any user who uses your service from the JS Library will get faster than downloading from your own server.

2. Increase the speed of loading the page

To avoid overloading the service, the browser limits the number of simultaneous connections, depending on the browser, which may be only two per room.
Use the CDN Public Library to load JS, so that more services on your local server can be done at the same time.

3. Better caching

The biggest benefit of using a CDN public library is that your users may not need to download jquery at all. No matter how powerful your cache is, if you use your own server to provide jquery, your users will have to download it at least once, and a user is likely to download many identical jQuery.min.js in their browser's cache. Copy versions, but when they first visit your site, these copy versions are ignored.

And when the browser detects the same version of the link to the CDN Public Library, it will know that this is the download of the same file, not only the CDN Public Library server will return a 304 (no need to modify the file instructions, the server file has not changed) to reply to a duplicate request, It will also command the browser to cache the file for up to a year.

This means that even if some people visit hundreds of of sites that use a CDN public library, they just need to download it once.

What CDN public libraries are currently available?

The most famous is the Google CDN JQuery library, but although it is loaded quickly, it is not particularly stable for well-known reasons.

Domestic provision of the same services have Sina SAE (http://lib.sinaapp.com) and Baidu Bae (Http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs).

Other public libraries: Https://developers.google.com/speed/libraries/devguide?hl=zh-CN#jquery

These are CDN Accelerated JS Library, the national loading speed is not bad.

How do I reference a CDN public library?

Take Baidu, for example, to load jquery, embed the code shown below in your Web page.

<script src="Http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>

If you want to cite Google's Cdn Public library and worry about Google's instability, then change the code to the following:

<script type= " Text/javascript " src=" https:// Ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js "> < /script>

<script Type="Text/javascript">! Window. JQuery && document. Write(' <script src= ' jquery-1.8.2.min.js ' ></SCRIPT>'); </script>

The meaning of this code is this: first to load the Google jquery library file, if the load fails, then directly load the jquery library file on its own server.

After referencing the public library, you also need to prohibit the loading of the jquery.js, see: WordPress Prohibit loading the Jquery.js method

Article Link: http://blog.gimhoy.com/archives/speed-up-your-website-js-libs.html

Website optimization: Reference CDN Public JS Library

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.