What exactly is a CDN?
How to set up a CDN with WordPress
The first step is to purchase your CDN package. I recommend using MaxCDN as they are reliable, inexpensive, and easily integrate with several WordPress plugins. Their packages start at $9/month or $90/year, and the cheap starter package is enough for most people. It’s a tremendous value when you consider how large of an impact it will have on your site’s performance. Once you purchase your CDN there, you will set up a “zone” for your website at MaxCDN.
Once you have correctly configured your zone, make sure to note down the CDN URL. There are several ways to integrate a CDN with WordPress, and for this tutorial we will be doing it with WP Super Cache. It’s technically a caching plugin, but we can easily disable page caching and just use it for it’s excellent CDN support. There are better methods for caching BuddyPress, as described here.
The first step is to install and activate WP Super Cache. Go to Plugins > Add New in your WordPress dashboard and do a search for the plugin. Install and activate.
Once you have the plugin activated, navigate over to Settings > WP Super Cache. Click on the “Easy” tab and then turn “Caching On” in order for the plugin to work, even though we won’t actually use any of the page caching features as they interfere with BuddyPress’ ability to serve dynamic content.
Click on the “Advanced” tab. Scroll down to “Accepted Filenames & Rejected URIs” and check every single content type to not be cached, and then click “Save”. This should effectively disable all page caching features.
Now to the fun part, where we actually integrate the CDN into WordPress. Click on the “CDN” tab. Check “Enable CDN Support”. Then add your CDN URL that you noted earlier into the “Off-site URL” and “Additional CNAMES” fields. It should look something like this: http://yourzone.youraccount.netdna-cdn.com
Purging the Cache
If you update your theme, you may notice that the CDN is still serving the old version of the files. Back at MaxCDN, you can go to Manage Cache for your Pull Zone and click to “Purge All” files. This will remove all of the files from the CDN, and they will get regenerated on subsequent page requests using your new versions.
wp_enqueue_script( 'buddyboss-main', get_template_directory_uri().'/js/buddyboss.js', array( 'jquery' ), '3.1.7' );
And the outputted URL will show as: