The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Programming Fundamentals" Dec 02 - 2:00 PM Eastern

Loading jQuery

Last updated on:

Load with Google API

<script src="" type="text/javascript"></script>
<script type="text/javascript">
    google.load("jquery", "1.2.6");
<script type="text/javascript" src="js/example.js"></script>

Direct Link to Google

<script type='text/javascript' src=''></script>

Check if loaded, only load if unloaded

var jQueryScriptOutputted = false;
function initJQuery() {

   //if the jQuery object isn't available
   if (typeof(jQuery) == 'undefined') {

       if (! jQueryScriptOutputted) {
           //only output the script once..
           jQueryScriptOutputted = true;

           //output the script (load it from google api)
           document.write("<scr" + "ipt type="text/javascript" src=""></scr" + "ipt>");
       setTimeout("initJQuery()", 50);
   } else {

       $(function() {
           //do anything that needs to be done on document.ready


Reference URL


  1. Nick
    Permalink to comment#

    so which one would be best to use, for speed, etc?

  2. Lessy
    Permalink to comment#

    There is no any difference in speed loading

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed