views:

70

answers:

1

I am loading the following javascript files from a CDN. Is there any way I can check if these have been loaded correctly and if not, load them from a local folder?

http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.min.js http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js

I know I can check the jquery file but not sure about the others. Any tips?

+6  A: 

In your HTML, you can do something like this:

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
  <script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>

The example shown is loading jquery from Google CDN and falls back on a local copy of JQuery if that fails.

Credits to HTML5 Boilerplate for showing the trick

Rajat
For ui and validate, do that same, checking for $.ui or $.validate
scottm
Thanks to both. Scottm - $.ui does the trick in checking if ui javascript is loaded but unfortunately $.validate does not. Any tips as how I check for the validate plugin?
Niall Collins
Anyone have any idea regarding checking if the validate plugin is loaded?
Niall Collins
Rajat
Cheers Rajat for your help
Niall Collins