If at all possible, I would not touch PhpBB's code, and rather resort to Apache's URL rewriting engine.
In PHPBB3, most of the static contents (by size) comes from the /assets/
subdirectory.
So if:
- you're using a rewrite-capable browser,
- have
.htaccess
or equivalent enabled
- and
mod_rewrite
or equivalent installed,
in the .htaccess
file you can place,
Redirect permanent /assets http://mycdnhoster.com/collector/phpbb3/assets
This allows you to enable/disable CDN very easily, and not worry about maintaining a modification to PhpBB's code.
Same goes for the "style" and "theme" static files. There is a slight performance penalty when the browser still hits your server only to be bounced somewher else, but with modern pipelined browsers that's not a real issue. Also, in most cases the redirected resource will be "remembered" by the browser that won't hit your server again (for some time at least).
Another possibility offered e.g. by NginX is to rewrite the output HTML. You can make it so all references to yoursite/static go to anothersite/differentpath/static using HttpSubModule.
Beware that some files might contain both absolute links that may no longer work, or relative links that may "fall" outside the scope of the rewrite, and so again no longer work. For example:
- javascript files using "delayed load" or "incremental/conditional loading" for plugin and similar features.
- CSS files containing references to fonts and background images (
url(../../../path/...)
).
Also beware, since you've specified pagespeed, that mod_pagespeed
may be incompatible with this type of URL rewriting, since it will parse the HTML and try to compress the resources referenced therein. So you might end up with all your hefty CSS's offloaded to a CDN, and them still downloaded instead from your server, embedded into an optimized, compressed and hard-to-recognize form in your single mod_pagespeed'ed local CSS reference.
I.e., in your html you have
<link href="/app/small.css" ... />
<link href="/static/big.css" ... />
<link href="/static/big2.css" ... />
and you expect the rewrite to get the static's loaded from offsite. If there were no further optimizations that is what would happen. Instead, your client sees a page rewritten by mod_pagespeed
that says
<link href="/app/small+big+big2.css?pagespeed&whatever" />
and he will never request anything in /static
, will never get redirected, but will instead request and download a compressed, optimized, but still larger than you'd wish, merged CSS from your server.