-6

Our site initial load time is huge. And I just spotted that currently there's a real mess when it comes to loading of scripts. There are multiple copies of same libraries and I'm trying to trace these down to which ones are really being used. So by cleaning these up, I've run into some questions:

  1. How to choose the best (most popular) CDN?

    For example jQuery offers 5 possible solutions. How can I be sure which one is the most common one? To my understanding even exactly the same file will be downloaded again if it's from a different host.

  2. Is there a way to check if the end-user already has jQuery from MaxCDN if not, then check Google CDN ... If neither one of these existed then try to load a copy from a chosen CDN. If that fails try loading it from somewhere else and finally a local copy?

  3. Is it even possible to check where the end-users copy of the script is from?

  4. Would this rather have a negative impact on the performance or a positive one?

Community
  • 1
  • 1
Artur K.
  • 3,263
  • 3
  • 38
  • 54

1 Answers1

0

If you have a large number of scripts, you may be better off combining and minifying your scripts and serving them from your own locally hosted CDN, or your web server. Oftentimes it's the number of requests that bottlenecks browsers instead of the filesize due to the fact that browsers can only download so many files at once. (FYI: IE7 allows 2. IE8+ and Chrome allow 6. Firefox allows 8 and the limit is configurable. Source) Minifying will reduce their size (often upwards of 50% or more) and combining will drastically reduce download times.

Regarding your questions:

  1. Even if you choose a popular CDN, there's a better chance than not that the user doesn't already have the jQuery library cached.
  2. No. This isn't possible. If you request a resource, the browser will try to download it. If it isn't available, the script loading will fail and you can handle downloading from an alternate source there. This is handy in cases where the CDN is down, but won't help in your situation.
  3. No. You can't check where their cached version of jQuery is from. This is likely due to the fact that such a feature would prove to be a security or privacy violation.
  4. Serving resources from a CDN is likely to have a positive impact. However, if you can serve all your resources from a single file, you're saving bytes as well as additional network requests.
Community
  • 1
  • 1
FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82