Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

How to Load jQuery from Google CDN to Use with JavaScript

Many web developers use multiple libraries, like Google Content Distribution Network (CDN), when creating a JavaScript application because each library has something special to offer. Each reference to a source outside the current page can trigger a security message. This is a helpful feature of many browsers today that’s often supported through a plug-in. Knowing where a page looks for resources can help keep a user’s machine safe.

However, when users begin seeing a lot of messages about sites they may not know about, many users throw up their hands and don’t allow these external sites access to the page. Consequently, your application fails because it lacks access to the libraries it needs to work. The answer is to use a single source to access the libraries you need.

The Google Content Distribution Network (CDN) is a series of libraries that you can use to create better applications. Google maintains all of these libraries on a common domain, which means that users don’t have to think so hard about each library you use in an application.

All the user needs to do is approve use of a single domain. Many developers rely on the Google APIs site to gain access to libraries such as jQuery. You see it all the time when working with pages online.

image0.jpg

When you want to use a particular library, you click its link on the page, and Google displays a script for accessing it. For example, when you want to use jQuery, you click its link to see a snippet similar to the one shown here.

<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>

With a simple replacement of the src attribute, you can use the Google CDN version of the library. Give it a try and you find that the example works just as it did before. It doesn’t matter which version of the library link you use, but the 1.8.3 version of jQuery is the most current version available as of this writing.

Your application may depend on a specific version of the jQuery library. If this is the case, you can access the version you want from the Google CDN. Simply replace the 1.8.3 part of the URL with the version you want. The Google CDN hosts all versions of jQuery except versions 1.2.4 and 1.2.5 because these two versions weren’t available for very long.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!