There are lots of “recommended” ways to do CDN’s in WordPress. Personally, I prefer to keep it simple and use the following code as an mu-plugin to simply buffer the complete output and rewrite the URL’s to match whatever you require. The URL’s to be rewritten can be controlled by simply filtering the ‘ryans_cdn_rewrites’ filter as shown further down the page.

<?php

/**
 * Ryan's simple URL rewriter for CDN's.
 * 
 * @copyright Copyright (c), Ryan Hellyer
 * @license http://www.gnu.org/licenses/gpl.html GPL
 * @author Ryan Hellyer <ryanhellyer@gmail.com>
 * @since 1.0
 */
class Ryans_CDN {

	/**
	 * Class constructor.
	 */
	public function __construct() {

		// Allow for ignoring CDN during testing
		if ( defined( 'IGNORE_RYANS_CDN' ) ) {
			return;
		}

		add_action( 'template_redirect', array( $this, 'template_redirect' ) );
		add_filter( 'rewrite_urls',      array( $this, 'filter' ) );

	}

	/*
	 * Filtering URLs.
	 *
	 * @param   string   $content   The content to be filtered
	 * @return  string   $content   The modified content after URL rewriting
	 * 
	 */
	public function filter( $content ) {

		// This is a critical point at which you must add rules for rewriting URL's
		$rewrites = apply_filters( 'ryans_cdn_rewrites', array() );

		// Loop through each rule and process it
		foreach( $rewrites as $origin => $destination ) {
			$content = str_replace( $origin, $destination, $content );
		}

		return $content;
	}

	/*
	 * Starting page buffer.
	 */
	public function template_redirect() {
		ob_start( array( $this, 'ob' ) );
	}

	/*
	 * Rewriting URLs once buffer ends.
	 *
	 * @return  string  The filtered page output including rewritten URLs.
	 */
	public function ob( $contents ) {
		return apply_filters( 'rewrite_urls', $contents, $this );
	}

}
new Ryans_CDN;

And here is the filter to control what URL’s are rewritten. You should modify this to suit your requirements as most sites will have specific requirements for how their URL rewrites are handled.

<?php

/**
 * Demo function which rewrites URLs to add a subdomain of .cdn.
 * 
 * @param  [type] $rewrites [description]
 * @return [type]           [description]
 */
function ryans_cdn_rewrites( $rewrites ) {

	$urls = array(
		home_url( '/wp-content/uploads/' ),
		home_url( '/wp-content/themes/' ),
		home_url( '/wp-content/plugins/' ),
	);

	foreach( $urls as $in => $out ) {
		$rewrites[$out] = str_replace( '://', '://cdn.', $urls[$in] );
	}

	return $rewrites;
}
add_filter( 'ryans_cdn_rewrites', 'ryans_cdn_rewrites' );

Here is another demo function can be used to dynamically convert http to https for a specific domain. Note, this function has not been tested yet.

<?php
 
/**
 * Demo rewrite function.
 * Rewrites http to https for a specific domain.
 *
 * @param  [type] $rewrites [description]
 * @return [type]           [description]
 */
function ryans_https_rewrites( $rewrites ) {
        $rewrites['http://domain.com'] = 'https://domain.com';
 
        return $rewrites;
}
add_filter( 'ryans_cdn_rewrites', 'ryans_https_rewrites' );