What's faster for including scripts, using CDN (Google) or storing them locally in website's root?

dzhi picture dzhi · Apr 30, 2010 · Viewed 15.5k times · Source

What's faster for including scripts, using CDN (Google) or storing them locally in website's root?

Answer

Nick Craver picture Nick Craver · Apr 30, 2010

If you mean the core jQuery libraries, use the google CDN for an internet-facing site (as opposed to an internal one).

The CDN has the following advantages you'll find hard to compete with:

  • More servers
  • The bandwidth (you don't pay for)
  • Geolocation (lower response time)
  • Redundancy
  • The optimized caching settings
  • Chance the user has already cached the file from there
  • Parallelized downloads, user can grab other content from your site at the same time

Though you can configure the cache headers just like they do, you probably can't serve the file faster. That being said, the library/CDN is only part of the puzzle. Miscellaneous plugins and code you have should also be minified, combined and served via gzip.