Adobe Business Catalyst Developer

  Please click our Google +1 Button if you find this helpful.

Loading jQuery - Loading Latest jQuery - Test If jQuery Loaded

Jonathan Beacher - Saturday, October 22, 2011

Below we explain several ways to install jQuery on your website:

  • Have your web page load the latest version from a CDN (content delivery network) like jQuery.com
  • Download the latest jQuery file, copy it to your web server, and load it locally.

Is jQuery Loaded On Your Site Already?

If you are using software like WordPress, or a content management system or development platform, or even a design template or theme you purchased, there's a good chance it already is loading jQuery because it is using it. You only need to load jQuery once so it's wise to create a test page to see if jQuery is already loaded. In the test page paste this script, then view the page in your browser. A popup message will tell you if you already have jQuery loaded or not.


<script type="text/javascript">
if (typeof jQuery == 'undefined') {  
    alert('jQuery is not loaded')  
} else {
    alert('jQuery is already loaded')
}
</script>

Loading Latest jQuery from jQuery.com

The following loads the latest version of jQuery from jQuery.com when you place this in your web page <head>


<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8"></script>

An advantage to loading this way is your web visitors may already have visited another site that loaded jQuery this way, in which case their browser will immediately use the copy already on their PC instead of wasting time downloading the file if you host it on your web site. This means your site loads faster.

Loading jQuery from Your Web Server

You can download jQuery here: jQuery.com.

Place the file in a folder on your own web server such as within /js and then include a load command in your web page <head> with a path to your copy:


<script type="text/javascript" src="/js/jquery.js" charset="utf-8"></script>

Loading jQuery Only If It's Not Already Loaded

Here's a clever way to automatically load jQuery only if it isn't already loaded. I use this when distributing software or design themes and I won't know if jQuery already exists or not. This version will load the latest version if there is no version of jQuery already running...

<script type="text/javascript"> if (window.jQuery == undefined) document.write( unescape('%3Cscript src="/js/jquery-1.6.4.min.js" type="text/javascript"%3E%3C/script%3E') );</script>
Comments
Post has no comments.
Post a Comment



Captcha Image

Trackback Link
http://www.atlantawebdesignga.com/BlogRetrieve.aspx?BlogID=11204&PostID=328470&A=Trackback
Trackbacks
Post has no trackbacks.