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

Hi,

I've manged to implement (hard code) one .css file via qa-theme-base.php to be served from a CDN (different URL from the base URL) & this is where I've stopped.

See e.g: http://homeq.co.uk/ source code for http://cdn.homeq.co.uk/qa-theme/Snow-ExtL/qa-styles.css?1.6.3

Is there a way to change the base url just for .CSS/JS/Images to all be served from the CDN?

I've got little to zero php experience.

Many thanks,

Simon.

Q2A Website http://homeq.co.uk/

1 Answer

+3 votes
by
selected by
 
Best answer
There are no images direct in the source for most Q2A themes, they are usually all background images in the CSS. So for that you can change the CSS to point to the CDN very easily.

For CSS files, you could check the $css_src variable inside the head_css() theme function and modify if necessary.

For JavaScript, currently there is no simple way. Unfortunately the <script> tags that reference external scripts are built in qa-page.php (lines 345-355). The only way to change this in a theme would be to check for "<script src=" inside head_script() and rewrite the link to point to your CDN, which wouldn't be easy.

It would be a slightly easier to make a core hack of those lines in qa-page.php to put your CDN URL in there.

I'll see if I can think of a way to make this easier in a future version of Q2A.
by
edited by
Seems to work great for .css
Step 1. Edited qa-theme-base.php found under qa-include
Step 2. Found and edited as below ('http://your_cdn_base_domain')

if (isset($this->content['css_src']))
                foreach ($this->content['http://your_cdn_base_domain'] as $css_src)
                    $this->output('<link rel="stylesheet" type="text/css" href="'.$css_src.'"/>');

Many thanks!

I'm still confused about the JS though. What should I hack?

$script[]='<script src="'.qa_html(qa_path_to_root().$script_rel).'" type="text/javascript"></script>';

?
...