Web Technology

Using CDN hosted Javascript libraries

Some of my favourites:


jQuery UI

More jQueryUI: (from the Official Blog post)




The Good

  1. Your site will load faster for most users
    – CDN always serves the files from the server closest to the user
    – They have set the proper cache header to enable client caching
    – If another site also uses the CDN hosted library, the user already have local cache, so loads even faster
  2. Save bandwidth and loading
    – JS files are not as large as images, but if your site is a popular one, the traffic and loading can adds up to a large number
  3. Simplify your development
    – If you’ve decided to use libraries hosted on CDN, there’s no need to download the library and put it in your web project again. Just copy and paste the HTML code and it’s working! It’s particularly useful for small scale projects and you never need to include the 3rd party code in your repository.

Drawbacks: things you should consider

  1. Reliability concerns
    – If the CDN is down, your site will follow (or at least looks broken). In fact It did happen, the Cloudflare was down last week, so the links from cdnjs was instantly inaccessible. One of the project I’m working on is affected, finally I changed to Google CDN libraries.
  2. Offline webapps
    – Obviously it won’t work if the user is offline, so if your web app will probably run offline, you’d better include the libs in your web project.
  3. Security
    – Using external links imposes a security risk on your system. If your link come from malicious sites, they can change the content of the library and, for example, add a key-logger script to eavesdrop the passwords. Use only links from trusted parties such as Google. ( or is it? 😛 )
  4. Lack of customization
    – If you want your own build of the library, say your own brew of jQueryUI theme, obviously you cannot do that. Most of these are vanilla version of the library.

Share your thoughts