A content delivery network (CDN) refers to a geographically distributed group of servers which work together to provide fast delivery of Internet content. A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos. The popularity of CDN services continues to grow, and today the majority of web traffic is served through CDNs, including traffic from major sites like Facebook, Netflix, and Amazon. A properly configured CDN may also help and it's required by most of speed tests and it's necessary to optimise your site for speed & performances.
If you have problem to properly setup a CDN service with Uncode, please paste these relevant codes in your Child Theme and change the variable "$ cdn_url" with the URL of your CDN.
Use this code for images:
/**
* Replace the URL of the generated Adaptive Images with your preferred one
*
* For example:
* 'https://example.com/wp-content/uploads/2018/10/image.png' to
* 'https://your-cdn-url-here.com/wp-content/uploads/2018/10/image.png'
*/
function uncode_child_resized_image_url( $url ) {
$cdn_url = 'https://your-cdn-url-here.com';
$site_url = site_url();
$new_url = str_replace( $site_url, $cdn_url, $url );
return $new_url;
}
add_filter( 'uncode_resized_image_url', 'uncode_child_resized_image_url' );
Use this code for self-hosted videos:
/**
* Replace the URL of a Self-Hosted video with your preferred one
*
* For example:
* 'https://example.com/wp-content/uploads/2018/10/video.mp4' to
* 'https://your-cdn-url-here.com/wp-content/uploads/2018/10/video.mp4'
*/
function uncode_child_self_video_src( $url ) {
$cdn_url = 'https://your-cdn-url-here.com';
$site_url = site_url();
$new_url = str_replace( $site_url, $cdn_url, $url );
return $new_url;
}
add_filter( 'uncode_self_video_src', 'uncode_child_self_video_src' );
Use this code for self-hosted audios:
/**
* Replace the URL of a self-hosted audio with your preferred one * * For example: * 'https://example.com/wp-content/uploads/2018/10/audio.mp3' to * 'https://your-cdn-url-here.com/wp-content/uploads/2018/10/audio.mp3' */ function uncode_child_self_audio_src( $url ) { $cdn_url = 'https://your-cdn-url-here.com'; $site_url = site_url(); $new_url = str_replace( $site_url, $cdn_url, $url ); return $new_url; } add_filter( 'uncode_self_audio_src', 'uncode_child_self_audio_src' );
Use this code if you have blurry images with CDN and ai-uncode.js returns 404 error:
/**
* Fix the URL of the ai-uncode.js * * 'example.com/wp-content/themes/uncode/library/js/ai-uncode.js' to * 'https://your-cdn-url-here.com/wp-content/themes/uncode/library/js/ai-uncode.js' */ function uncode_child_fix_ai_script_path( $url ) { $new_url = 'https://your-cdn-url-here.com' . $url; return $new_url; } add_filter( 'uncode_ai_script_path', 'uncode_child_fix_ai_script_path' );
Comments
0 comments
Article is closed for comments.