Monday, August 11, 2014

Adding jQuery reference url to a page if the jquery is not loaded from local project references

In lot of the web applications, adding jquery references is a common practice. There can be scenarios where the jquery that has been referenced in your page might not be loaded due to Connectivity Issue or for some other reason and you don't want the page functionality to break because jquery is not loaded.

The below piece of code will load the jquery from CDN, if the juqery is undefined in your page



The LoadResources function will first check if jquery is defined or not. If not defined, it will try to create a scrip tag and to the script src attribute it will set the jquery CDN url. After setting the src attribute of the script tag to the jquery CDN url, add that script element reference to the head tag

Check jquery sit to get all valid CDN url's