Search code examples
javascriptjqueryperformancehref

Is there a speed difference between using externally hosted scripts and locally hosted ones?


I've been using the jQuery library hosted by Google on my site. Will it load quicker if I host it locally?


Solution

  • Here are a few factors to think about:

    1. Cache. If you are using the Google hosted jQuery, and another website is using the same version of jQuery hosted with Google, it will be cached locally already. Many ISPs will also cache this file for faster delivery to their customers as well.

    2. Parallel downloading. Because jQuery will be downloaded from another domain, your maximum connection limit per domain (usually 4 per browser) won't have to queue jQuery.

    3. Multiple locations. Google has servers all over the world, which results in faster downloads for international users.

    Now that said, it is possible that your servers could be lightning fast with multiple locations, and setup for parallel downloading across different subdomains. Probably a bigger performance factor is the load priority that will be determined by load order of CSS and Javascript: http://code.google.com/speed/page-speed/docs/rtt.html#PutStylesBeforeScripts

    Hope that helps!