1. Back To Blog

3 important ASP.NET jquery CDN Interview questions with answers

What is CDN (Content delivery network)?

In CDN multiple copies of the website is copied on different geographical servers. When users request website content which have CDN enabled depending on their geographical location content is served from the nearest geographical location server of the user.

So if a user is from India, the Indian CDN server will serve request for Indian users. This leads to faster delivery and good backup in case there are issues.

 

For Jquery files which are the popular CDN's?

There are two popular CDN's Microsoft and google.

 If you want to reference google CDN Jquery files you can use the below script.

 

<script type="text/javascript"

    src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">

script>

 

If you want to use Microsoft CDN you can use the below javascript.

 

<script type="text/javascript"

    src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">

script>

 

How can we reference local Jquery files if CDN fails ?

Many times it's possible that Microsoft and google servers can go down for some time. So in those situations you would like your page to reference jquery files from local server.

So to implement a CDN fallback is a two-step process :-

 

First reference the CDN jquery. In the below code you can see we have reference Microsoft CDN jquery file.

 

http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">script>

 

Now if Microsoft CDN is down then the Jquery value will be "undefined". So you can see in the below code we are checking if the Jquery is having "undefined" value then do a document write and reference your local Jquery files.

 

if (typeof jQuery == 'undefined')

  document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));

}

 

Below is the full code for the same.

 

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">script>

<script type="text/javascript">

if (typeof jQuery == 'undefined')

  document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));

}

script>

 

All the above three ASP.NET JqueryInterview questions with answers are provided by questpond.com

 

The above questions are taken from the famous .NET Interview question book published by Bpbpublications , you can know more about the book from http://www.flipkart.com/net-interview-questions-6th/p/itmdyuqzdqx8cvqx

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social