What is CDN?

CDN is an acronym for Content Distribution Network or also called Content Delivery Network. It is a group of computers placed at various points connected with network containing copies of data files to maximize bandwidth in accessing the data. In CDN, a client accesses a copy of data nearer to the client location rather than all clients accessing from the one particular server. This helps to achieve better performance of data retrieval by client.
There are two leading CDNs available that host jQuery files:

a) Microsoft – A jQuery file can be loaded from Microsoft AJAX CDN using the following tags in your page:
<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js">
b) Google – A jQuery file can be loaded from Google CDN using the following tag in your page:
<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
Benefits of loading jQuery file from CDN:
  1. The page loads faster as the jQuery file need not be downloaded when the web page is requested.
  2. Since the jQuery file is not loaded from your server, it saves the bandwidth.
  3. Scalability - the CDNs generally place the jQuery file on the servers located at different geographical locations so that they load faster. So irrespective of where your user is browsing your page, your application runs well.
How to load jQuery file in case CDN in not available:
It may happen that the CDN (which you have used) in unavailable. This is the case when you should load your local jQuery file that is available on your server so that all jQuery related functionality still works fine on the web page. Given below is the code to do so:

<!-- START - jQuery Reference -->
<script type="text/javascript" language="Javascript" 
    <script type='text/javascript'>//<![CDATA[
        if (typeof jQuery == 'undefined') {
        src='/Script/jquery-1.4.1.min.js' type='text/javascript' %3E%3C/script%3E"));
<!-- END - jQuery Reference -->

Replace the above highlighted path with your own jQuery file path on the server.

1 comment: