Fail-Proof Method to load jQuery Library via Google AJAX Libraries API

Posted in Web Development on 21 October 2009 2 comments

I used to load jQuery library via Google AJAX Libraries API to save my bandwidth. It works in all browsers at the beginning, including Internet Explorer. However, my jQuery scripts suddenly failed to load in Internet Explorer 6.

I avoid using google.load()

Since the problems with google.load() were discussed everywhere on the web (1, 2, 3), I did not use google.load() method, in fact I use the direct URL to the jQuery library js file like below:

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

By theory, the script above should run without any failure. However, it suddenly fails to load in IE6 without reason. It causes my page to have error.

The (Hopefully) Fail-Proof Method

However, with this few lines below, the problem is fixed and it works in all browsers.

<script type="text/javascript" src=""></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write('<script type="text/javascript" src="jquery.js"><\/script>');

What it does:
1. Load jQuery 1.3.2 library via the direct URL at google
2. The second line checks if “jQuery” is undefined (not loaded)
3. If so, load the jQuery library from your website.

It works for me, at least!

As stated above, it works in my case. I haven’t try using this method along with other plugins so it’s possible that it may not work with you.

It still don’t work!

If it still doesn’t work, most likely it is due to the “$ is not a function” error.


Posted by Zen on 21 October 2009 • 13,313 visits 2 comments
Tags :

or Subscribe to specific category only :


Neil Osman says:

Hi, i just run across this problem. Strange thing indeed. Maybe it’s a Google policy thing against IE6?
Do you know if this happens only with JQuery?

zen says:

@Neil Osman, I only use jQuery so I am not sure about others.

Anyway, I found the solution to problem in MSIE, it is not related to google. In fact the error message is “$ is not a function”

To solve that, read this

I will update the blog post later.

Leave a Reply

You must be logged in to post a comment.

Previous Post
Next Post