XF 2.0 Best way to handle CDN configuration in XF2?

Mike Fara

Active member
Hello fellow XF2 people, mods, and devs. In the past, for CDN usage, we used something in config.php like:

Code:
$config['javaScriptUrl'] = 'https://cdn.whatever.com/js';
$config['externalDataUrl'] = 'https://cdn.whatever.com/data';

Is this still supported? Clearly not, as data and js no longer exist. What would be the proper usage now, if any? Thank you in advance.
 
Hi @Brogan

Basically, I moved out the old config.php in favor of the new one in XF2. If you're saying those lines of code variables can still be used, I will give it a try. I read the manual and I'm uncertain if theres additional assets that can be moved to the CDN using additional variables. Perhaps I am mistaken. Also, not to go off topic (but I will), we use PHP 7.0's Zend Opcache. Does this need to be set as a parameter such as

Code:
$config['cache']['enabled'] = true;$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
$config['cache']['cacheSessions'] = false;

Or is front-end cache presumed on by default in this version? Sorry for the confusion and thanks for your reply.
 
Thank you. Would you recommend running memcached with Zend Opcache already enabled in PHP7 or do you think this is overkill? Mind you Im using Litespeed and not nginx. Sorry for the 20 questions here.
 
For larger installations, it can be worth implementing caching to save on queries and processing time.

If you do decide to implement session caching then Memcached is the one we would recommend.
 
For larger installations, it can be worth implementing caching to save on queries and processing time.

If you do decide to implement session caching then Memcached is the one we would recommend.
Hmm yes, Litespeedtech had a great plugin for 1.x to use their cache engine, but at present time, it looks like they are working on a rewrite for XF2. Perhaps running memcache wouldn't add too much overhead, so thanks for that reply.

Here is another one, and I promise, this will probably be the last one:

Even though the external data URL is set to our CDN, and is working for avatars, I cannot help but notice that XF Media Gallery images are still referrencing /media and attachments are still being pulled locally. Is there something in the style editor that needs to be altered? We also use htaccess rewrites to try to catch all images, but it doesn't look like it is 100% effective right now. This makes me think that the path to attachments may be explicitly defined somewhere in the default XenForo styles as I believe it may have been in 1.x. Do you know where I would alter the attachment path (and possibly XenForo media gallery path) in the default XenForo theme, or is there some other mechanism to fix this?

For example, avatars and header images will point to the CDN, but attachments and media gallery images do not. I can only conclude that this is something defined in the actual style.

For example, an attached image will look something like this in the HTML (example):

Code:
<img class="lg-object lg-image" src="https://xenforum.com/attachments/win10-mike-july-png.30428/">

Similarly, non-image attachments appear in the HTML like this (example):

Code:
<a href="/attachments/w7f_16-12-2017-zip.35593/" target="_blank" title="W7F_16-12-2017.zip">W7F_16-12-2017.zip</a>

And finally, media gallery images appear in the HTML as (example):

Code:
<img src="/media/pups-image-jpg.717/full" class="js-mediaImage">

They are not pointing to, for instance, cdn.xenforo.com. Not sure what the solution is for this?

Thank you.
 
Just insert in config.php..
PHP:
$config['externalDataUrl'] = "https://cdn.domain.com/data";
$config['javaScriptUrl'] = "https://cdn.domain.com/js";
 
Hmm yes, Litespeedtech had a great plugin for 1.x to use their cache engine, but at present time, it looks like they are working on a rewrite for XF2. Perhaps running memcache wouldn't add too much overhead, so thanks for that reply.

Here is another one, and I promise, this will probably be the last one:

Even though the external data URL is set to our CDN, and is working for avatars, I cannot help but notice that XF Media Gallery images are still referrencing /media and attachments are still being pulled locally. Is there something in the style editor that needs to be altered? We also use htaccess rewrites to try to catch all images, but it doesn't look like it is 100% effective right now. This makes me think that the path to attachments may be explicitly defined somewhere in the default XenForo styles as I believe it may have been in 1.x. Do you know where I would alter the attachment path (and possibly XenForo media gallery path) in the default XenForo theme, or is there some other mechanism to fix this?

For example, avatars and header images will point to the CDN, but attachments and media gallery images do not. I can only conclude that this is something defined in the actual style.

For example, an attached image will look something like this in the HTML (example):

Code:
<img class="lg-object lg-image" src="https://xenforum.com/attachments/win10-mike-july-png.30428/">

Similarly, non-image attachments appear in the HTML like this (example):

Code:
<a href="/attachments/w7f_16-12-2017-zip.35593/" target="_blank" title="W7F_16-12-2017.zip">W7F_16-12-2017.zip</a>

And finally, media gallery images appear in the HTML as (example):

Code:
<img src="/media/pups-image-jpg.717/full" class="js-mediaImage">

They are not pointing to, for instance, cdn.xenforo.com. Not sure what the solution is for this?

Thank you.


Same here, trying to set cdn but only avatars and thumbs are served...
 
Works great for me
Is that add-on could solve for my situation ?
 
lol, then do you khow to handle the 2~3T TB bandwidth per day for video attachment ?
Note by default, even on the $200/month plan, that Cloudflare doesn't cache video files like .mp4.

It's against their terms of service:

see section 2.8:

"2.8 Limitation on Serving Non-HTML Content
The Service is offered primarily as a platform to cache and serve web pages and websites. Unless explicitly included as a part of a Paid Service purchased by you, you agree to use the Service solely for the purpose of serving web pages as viewed through a web browser or other functionally equivalent applications and rendering Hypertext Markup Language (HTML) or other functional equivalents. Use of the Service for serving video (unless purchased separately as a Paid Service) or a disproportionate percentage of pictures, audio files, or other non-HTML content, is prohibited."

There is lots of discussion about this issue, for example: https://community.cloudflare.com/t/mp4-large-files-cdn/550

And Cloudflare may disable you for it, as experienced by this guy: https://community.cloudflare.com/t/...rms-of-audio-video-static-html-content/101075

You can use rules to specifically cache single video files (like we do for a mp4 that is a background on a home page), but other than that...

Note Cloudflare's entreprise plans begin at several thousand dollars per month.

If you have that much traffic, you might want to rent a server and pay for the bandwidth... And keep the video on a subdomain different than images cached by a CDN.
 
Top Bottom