Thursday, February 24, 2011

Ways to use jQuery files


The best way for us to use the JQuery library is to attempt to load the jQuery hosted at Google. By this you have the latest jQuery files. But it can fail in following situations:

  1. Your web application is an intranet application and depending on the user rights of the person logged into the computer, they may not be able to access internet
  2. Maybe this Google file is blocked for you
We have few options here:

  • Connect to the Microsoft hosted version of jQuery (again if internet is down, it breaks)
  • Try to work out the code in such a way that it first checks the internet and then if not available, checks the local version (which is the best)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.2/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
    document.write(unescape("%3Cscript src='/path/to/your/jquery on your server' type='text/javascript'%3E%3C/script%3E"));
}
</script>

1 comment: