MyBB Community Forums

Full Version: jQuery: @ ajax.googleapis.com = Faster?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Will loading jQuery from
http://ajax.googleapis.com/ajax/libs/jqu...ery.min.js
be faster since many people already have it cached in their browser?

Oops...
Back to Step 1:
If your site (your.com) uses the ajax.googleapis.com for jQuery, and one of your recent visitors also stops at my site (my.com), then will ' jquery.min.js ' already be cached in their browser.
^^^
For most users (with default settings), I think the answer to Step 1 is 'Yes.'

Part 2: Since many people already have jQuery cached in their browser, then it is faster to use ' ajax.googleapis.com '.
  • Is the above correct?
Thank you


That's right. It's faster and more efficient to use Google's hosted jQuery than to host it on your own server.
Great, just wanted to double-check, thanks Ferron.

It's faster and more efficient...
^^^
Looks good so far:
Occasionally, Google ads (or other scripts) cause a site to load slow while waiting for a response. Has anyone noticed this with ajax.googleapis.com?

Google ads have nothing to do with them hosting jQuery libraries for you.
(2010-12-10, 07:17 AM)Alex Smith Wrote: [ -> ]Google ads have nothing to do with them hosting jQuery libraries for you.

OK fine,
They both use javascript and at least one can (sometimes) cause obvious delays. Toungue

Javascript will always cause delays as it's handled on the users end. Even if the server is fast javascript can make it seem slow.
Thanks Alex, you are correct.
I like the idea that the primary jQuery file (from the Google address) is already in many people's browser cache.
External JavaScript comes with many pitfalls though. What happens if their server is down, hacked so it contains malware, or simply not reachable by the client due to company firewall settings, or if they decide to move the file elsewhere... Just because it's Google doesn't mean you won't ever run into problems.

The benefits are very little in comparison - slight chance of the file already being cached, when it will be cached either way after the first visit; if it's not cached it will likely be slower to load than from your own server. So no, I would not do that...
^^^
Hi frostschutz,
Exactly why I never used to include external JavaScript. IMO, everything you said is valid / good advice, except perhaps this part:
...slight chance of the file already being cached,

Many people would already have it cached, since jQuery is so popular.

#
I might try this:
If (for example) you have ~20 to 30 domains on a VPS, and use this code:
<script type="text/javascript" src="http://main_local_domain.com/js/jquery.min.js"></script>
...using that same code for every domain, then any visitor to more than one local domain will load jQuery only once.





(2010-12-10, 10:24 AM)frostschutz Wrote: [ -> ]External JavaScript comes with many pitfalls though. What happens if their server is down, hacked so it contains malware, or simply not reachable by the client due to company firewall settings, or if they decide to move the file elsewhere... Just because it's Google doesn't mean you won't ever run into problems.

Which is why I always do the following:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>  
<script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>

If it fails to load from Google, then just fallback to a local copy.
Pages: 1 2