Return to Snippet

Revision: 15231
at June 27, 2009 16:15 by iroybot


Initial Code
<script type="text/javascript"> 
	/* only load jQuery if not present */
	if(typeof jQuery == 'undefined') {
		document.write("<script type=\"text/javascript\"   src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>");
		var __noconflict = true;
	}
</script>
<script type="text/javascript"> 
	/* if Google is down */
	if(typeof jQuery == 'undefined') {
		document.write("<script type=\"text/javascript\" src=\"/lib/js/jquery.min.js\"></"+"script>");
		var __noconflict = true;
	}
</script>
<script type="text/javascript" src="/lib/js/functions.js"></script>

Initial URL


Initial Description
1) if jQuery is already loaded into a browsers' cache -> do nothing
2) if the object is undefined, write a script-element into the source which references google's minified jquery file.
3) if jQuery is still undefined (let's assume Google is down). write a script reference to our local copy into the source.

You could also use the if statements to define different JS files for the frontend and the backend.
(as seen on www.ie6update.com)

Initial Title
Conditional jQuery Implementation

Initial Tags
script, jquery

Initial Language
JavaScript