3

I've found a little script here in stackoverflow which allows me to load the JQuery lib from Google with a fallback to the local server. So I implement this in my site.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script> 
<script>window.jQuery || document.write(&apos;<script src="js/jquery-1.6.4.min.js">\x3C/script>&apos;)</script>

But firebug show me a syntax error after implementation:

syntax error
 window.jQuery || document.write(&apos;...uery-1.6.4.min.js">\x3C/script>&apos;)

Someone knows a workaround or a fix?

Kind Regards

3 Answers 3

4

This one is the correct escaping for it:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js" /></script>    
<script>window.jQuery || document.write('<script src=\"js/jquery-1.6.4.min.js\"\>\</script\>')</script>

Working Demo.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this: window.jQuery || document.write('');

No need for the entity shenanigans.

EDIT: interesting. It is dumping it out inside the script block, and then the javascript parser is falling over. Try this instead (I deliberately botched the CDN url so it would force the download of the local copy):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.4/jquery.js"></script>
<script>window.jQuery || function(){ var script=document.createElement('script');script.src='js/jquery.js'; document.getElementsByTagName('head')[0].appendChild(script); }();</script>

1 Comment

after this one firebug tells me "unterminated string literal window.jQuery || document.write('<script src="js/jquery-1.6.4.min.js">"
0

This snippet is working for me.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
   !window.jQuery && document.write('<script src="<?php echo $this->webroot; ?>js/jquery.min.js" type="text/javascript"><\/script>');
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.