Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Q2A Core by

The default way of including jquery is defined in qa-page.php frmo line 706:



and results in the following HTML: 

<SCRIPT SRC="./qa-content/jquery-1.7.2.min.js" TYPE="text/javascript"></SCRIPT>

However, as I do on other sites as well, I would like to load Jquery from a CDN and just fall back on the local jquery if the CDN is down, I do it like that:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>window.jQuery || 
    document.write('<script SRC="./qa-content/jquery-1.7.2.min.js"><\/script>')</script>

How can I implement this code instead of the default one?




Q2A version: 1.5.4

2 Answers

+1 vote
selected by
Best answer
Hi Kai.

Well, I'd just comment out original code in qa-page.php and then add necessary code in head_script() function within my own theme.

But if you want to get complete upgradeability, I think, you should parse $this->content['script'] within head_script() function override before calling parent::head_script() and unset jQuery's entry (I think, code like false!==strpos('qa-content/jquery',$scriptItem) would be enough to detect necessary entry). It's a rather bad thing in fact, but it looks like Gideon didn't left us anything better. There should be no html rendering in the core at all, but, alas, it's not the case...
thx for your answer, how do you replace: $qa_content['script_rel']=array('qa-content/jquery-1.7.2.min.js'); with your own code?
I'm sorry, I'm not sure I understand the question. Could you please explain? :)
+2 votes
I am getting old, thanks a lot Scott!