Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
656 views
in Q2A Core by
I am working on implementing CDN on the Q2A site for loading static resources like CSS, JS, images and font files.

What is the best way to replace the urls only on these files to load from a CDN url domain location instead of the origin server.  ?
Q2A version: 1.7.4

1 Answer

+1 vote
by

You can create an advanced theme, and override the head_script() function to check for scripts and change the URLs. Something like this:

public function head_script()
{
    if (isset($this->content['script'])) {
        foreach ($this->content['script'] as $scriptline) {
            $scriptline = str_replace('q2a-url', 'cdn-url', $scriptline);
            $this->output_raw($scriptline);
        }
    }
}

Where 'q2a-url' is the local/origin URL, and 'cdn-url' is the address for that URL on the CDN.

...