1

I was wondering if it is a good idea to check whether jQuery library is loaded from the external host (even if it is the GoogleAPI) before starting to use it in your code?

In general, what are some good practices to use for the applications which heavily rely on some external JS libraries, in order to assure that all the necessary resources are loaded and all UI items initialized to perform their functions?

Thanks!

spacemonkey
  • 19,664
  • 14
  • 42
  • 62
  • 1
    It's not a bad idea to have a local copy with a fallback in case your CDN is down. http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go – James Montagne Jan 20 '14 at 15:37

1 Answers1

1

CDN use for .js libraries

Pros:

  • reduces load on your server
  • stays up-to-date (if you choose to use "latest version")
  • faster initial loading by client
  • potentially already cached by client

Cons:

  • Code changes unless you point to specific version
  • reliance on 3rd party system for delivery of your product (their failures are your failures)
  • potential cross domain scripting issues

My thoughts: Usually the CDN (if it a real CDN) has a significantly lower failure potential that any server your files might be hosted on. Using a fallback in addition to the CDN is the best approach. Use "//cdn.com/js/files.js" instead of specifically naming the protocol; that way if you serve pages under HTTPS or HTTP they both work fine and only use the CDN's SSL when necessary.

DanJGer
  • 514
  • 3
  • 4