Speed up your site with a CDN

xF1 Guides Speed up your site with a CDN 2015-07-18

No permission to download
Compatible XF Versions
  1. 1.3
  2. 1.4
  3. 1.5
What is a CDN?
A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance. CDNs serve a large fraction of the Internet content today, including web objects (text, graphics and scripts), downloadable objects (media files, software, documents), applications (e-commerce, portals), live streaming media, on-demand streaming media, and social networks.

Content providers (eg. XenForo sites) pay CDN operators to deliver their content to their audience of end-users. Besides better performance and availability, CDNs also offload the traffic served directly from your own site, resulting in possible cost savings and load reduction on your server.

xenforo_com_community_attachments_cdn_explained_png_111714__.png


KeyCDN is a powerful and easy to use Content Delivery Network (CDN).
I have used several (MaxCDN, CDN77, Cloudfront), and found it to be the best and cheapest. It's Pay As You Go, so you only pay for what your site uses. They support SSL and SPDY, as well as your own site being HTTPS (not all CDN's do!). And best of all, it's only $0.04 per GB (for the first 10 TB) of CDN data used.
As an example, an average XF site with around 500k page view per month would use around 150GB CDN traffic costing you only approx. $6 per month.


Why Use a CDN?
The number one reason for using a CDN is to improve your user's experience in terms of speed, and as we know - speed matters! Ensuring a consistent experience for all your users is important.

Your XenForo site may be hosted in a particular region (where its's cheaper!), but have the majority of its users coming from an entirely different region - for example, if your site is hosted in North America, but if a good chunk of your users come from Europe or Australasia - their speed will not be as fast as it could be.

A global CDN would allow users from Europe or Australasia to download static content from a closer source. Instead of spanning the Atlantic ocean to retrieve data, they can connect to a server in say, London, Melbourne, to get the same data. This reduces latency and provides a faster loading of your XenForo community site.

CDNs not only ensure a faster experience to your users, but they also help to prevent site crashes in the event of traffic surges - CDNs help to distribute bandwidth across multiple servers, instead of allowing one server to handle all traffic.

gtmetrix.com_static_r124_resources_why_use_a_cdn_cdn_example.png


Steps to setup a CDN for your XenForo site using KeyCDN

Create your CDN account, and setup your site within it....
  1. Visit KeyCDN and click the 'Sign Up' button/link in the top right-hand corner, and create you 30 days free trial account.
  2. Activate your account, following the instructions emailed to you.
  3. One logged-in, on the left-hand side navigation menu, go to 'Zones'.
  4. Click '+New Zone'.
  5. Enter your Zone Name (eg. your XF Site Name), set your Zone Status to Active, and your Zone Type to Pull
  6. Enter your Origin URL being your XF site URL (eg. http://www.myXFsite.com)
  7. Click Save and return to the Zones page.
Configure your XenForo site to use the CDN....
  1. Connect via SSH, SFTP, or FTP to your server
  2. Change to the 'library' folder of your site
  3. Edit file 'config.php' and add the below two lines at the bottom, replacing [ZoneURL] with your Zone URL displayed on the Zones page. (eg. http://<MyXFSiteName>-fcc.kxcdn.com)
    Code:
    // CDN support
    $config['externalDataUrl'] = 'http://[ZoneURL]/data';
    $config['javaScriptUrl'] = 'http://[ZoneURL]/js';
  4. Save the above addition to your config.php
  5. Login to your XenForo sites admin area (eg. http://www.myXFsite.com/admin.php)
  6. Navigate to Appearance -> Style Properties -> General
  7. Within the 'Path to Images' field, add your Zone URL to the beginning. Eg. changing "styles/<yourstyle>" to "http://<MyXFSiteName>-fcc.kxcdn.com/styles/<yourstyle>"
    xenforo_com_community_attachments_screen_shot_2015_07_18_at_19_38_30_png_111709__.png
  8. Click 'Update Style Properties' to save
Done!

Your site is now using your CDN to deliver static files (style images, attachments, javascript, etc.) from servers closest to your users. Visit your Real-time Logs or Real-time Stats pages to see your site traffic using your CDN. Other reporting, such as Analytics and Geo Stats tells you how much data and from which locations your users are consuming your CDN.

If your site is HTTPS, then see this post in discussion for the advanced settings to use with shared SSL.

Before your free trial (and $5 bonus credit!) expires, visit the Payment page to buy additional credits for your account, using PayPal or your credit card.


Disclaimer: The links to KeyCDN are using an affiliate link that gives you $5 sign-up credit, and me a percentage of your first payment if you remain beyond the free trial period. Fair enough for writing this guide and steps eh? :)
Author
AnimeHaxor
Downloads
8
Views
2,342
First release
Last update

More resources from AnimeHaxor

Latest reviews

D
  • Deleted member
  • 5.00 star(s)
  • Version: 2015-07-18
Awesome post. Very helpful and easy to set-up. Many thanks ;)
731Threads
2,287Messages
63,882Members
AcunacusaurusLatest member
Back