Posted By

iroybot on 06/27/09


Tagged

script jquery typeof


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

LeslieOA
iroybot
nerdfiles


Conditional jQuery Implementation


 / Published in: JavaScript
 

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)

  1. <script type="text/javascript">
  2. /* only load jQuery if not present */
  3. if(typeof jQuery == 'undefined') {
  4. document.write("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>");
  5. var __noconflict = true;
  6. }
  7. </script>
  8. <script type="text/javascript">
  9. /* if Google is down */
  10. if(typeof jQuery == 'undefined') {
  11. document.write("<script type=\"text/javascript\" src=\"/lib/js/jquery.min.js\"></"+"script>");
  12. var __noconflict = true;
  13. }
  14. </script>
  15. <script type="text/javascript" src="/lib/js/functions.js"></script>

Report this snippet  

You need to login to post a comment.