Hosting jQuery via Google, anyone have trouble with this?

Associate
Joined
4 Jan 2011
Posts
2,124
I've done this a couple of times recently and just realised that I used the same method to make it work each time. The theory being that if you use this:

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

Then it should use Google's copy,which is fine. However, when I upload a site to my hosting area for testing, this doesn't work as it does locally.

Instead, I have to get a copy of the jQuery library uploaded to the hosting area, and link locally instead so that it works.

This is the weird part. If I remove the local link, refresh the page, and then add the Google API link into the page and refresh it again it works fine.

I've made sure the copy I uploaded was removed so it didn't load it from there, but it seems like an odd way to have to go about getting it to work.

On top of this, I double checked that I removed the cache etc... to make sure it isn't hiding somewhere, and seems to be running from Google's link fine.

If anyone can clarify this weirdness I'd be greatful. I don't have a massive wealth of experience with jQuery stuff yet, but this seems like it should be as simple as dumping the link into the page and the library should be accessible.

Cheers :)
 
You sure there isn't something server side that is blocking external scripts?

Also, if you're loading jQuery from a CDN, you should really have a local fallback, like this...

Code:
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="local/path/to/jquery-1.10.1.min.js"><\/script>')</script>
 
Hey buddy, thanks for the advice on the fallback, I'll make use of that =]

In terms of the block, I don't think there is a block in place. Having done the tests I mentioned, I used another PC in the house that has never been used for testing on this project and the external reference works fine.

I assume from your answer there is nothing that might explain what was happening.

Out of curiosity, if I had tested the page using a locally available copy of the jQuery library, and then replaced that with a script telling it to go off and find the external one, would this mimmick the request for the external library because it has already accessed the local copy once, and stored it in temp files ready to be used?
 
That doesn't make a lot of sense as far as I can tell. The idea is not really that you are using googles copy, its that everyone who visits your site will already have that resource cached from loading another site that uses it thus your users won't have to download that resource.

On the testing server, what does the web developer console in FF / Chrome complain about.
 
After doing some digging, I checked with 123-reg and they say there is nothing to block a script like that, which is something.

In terms of checking I couldn't see anything that was complaining. As I'm using an animated scroll script and fancybox, so they still "work" just without the bells and whistles that the scripts provide.

I did a test last night as well with a quick and dirty HTML page to do a simple scroll, referencing a different external library that I know I've not made use of before and it seemed to work fine.

I think I'll have to put it down to an odd circumstance for now, as it all points to me doing something odd.

Thanks for the input though guys :)
 
you could always use firebug or something and use NET tab to see whether your browser actually "loads" it in the first place.

Also from experience, if there is a problem with JS code (anywhere, i.e. on your own custom one) then it may have trouble executing any more JS code.
 
Ah that's cracking. I have to admit I use Firebug to check HTML but haven't looked at any of the other things it can do. I've done the check on the quick page last night and it shows that it requests it. Awesome :)
 
Well in the grand scheme of things it seems to have just stopped being an ass, but the NET side of Firebug shows me that it definitely calls to it as it's supposed to, and works as it should. So yep all sorted, cheers :)
 
If you haven't got jQuery working, any plugin depending on it will not work period. It wouldn't just be working without the bells and whistles. If a plugin isn't working that doesn't usually point to jquery as the issue. It would have web developer tools errors along the lines of 'file not found'
 
Back
Top Bottom