Why to load jQuery file from CDN?

 Posted by Sheonarayan on 7/20/2011 | Category: jQuery Interview questions | Views: 3607 | Points: 40

You may ask that if we can load the jQuery file from our own server why to load it from the CDNs. The answer is logical and very simple. The browser behavior is that whenever it loads any webpage, it keeps related files (eg. Javascript file, CSS file and Images) used for that page into its cache (also called history). When next time the user browses any web page, browser loads only those files that are new or modified and is not available in the browser cache or history. In this way, browser improves its performance and loads the page.

The possibility is that if more and more websites are using CDNs, the user might have already browsed some other web pages that is using CDNs jQuery file and that file may have into browser cache; so when user browse your page and you are also using CDNs file, the older cached version of jQuery file will be used. In this way your page will load faster as browser will not have to load the jQuery file for your page again.

The benefit
1. Faster page load as jQuery file need not to be downloaded
2. Saves your bandwidth as jQuery file is not loaded from your server
3. Scalable - generally CDNs place these files on the servers located at different geographical locations of the world so that they load faster so irrespective of from where your user is browsing your page, your application runs well.

Source: http://itfunda.com/jquery-how- | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response