CDN Not Working, Files Not Sent To CDN

If, after activating the CDN option and entering your CNAME in WP Rocket you see that your files are not being served from your CDN, please check the following. 

In your WordPress dashboard, go to:

Settings > General

and check how your site URL is written - does it have the www in front of the domain? 

Technically speaking, the www and non-www version of your domain name are 2 separate domains. When re-writing the URLs of your files to your CDN, WP Rocket looks for the domain version as specified in your Site Address settings. Any other version is considered external and will not be re-written with the CDN url.

So if you use www in your site settings, you should make sure all links to your files also contain it, otherwise they will not be re-written to your CDN. 

In this example, there are two images, one image url uses http://www.lucybeer.com and one uses http://lucybeer.com

Only the the first image will get re-written to the CDN, the other will not because of the lack of www: 

Relative Links To Assets

Using relative links to assets is incompatible with the CDN function. You must use absolute links containing a domain name. If there is no domain name, we cannot detect and rewrite them using your CDN name. 

For example, this type of format will not work: 
/wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js?ver=2.2.10

This will work:
http://example.com/wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js?ver=2.2.10

CDN for logged-in users without cache

The replacement of your domain URL to the CDN URL by WP Rocket is done in two pass.

The first one uses available WordPress filter hooks whenever possible, and will be done for both cached and not cached pages:

  • template_directory_uri
  • wp_get_attachment_url
  • smilies_src
  • stylesheet_uri
  • wp_get_attachment_image_src
  • wp_calculate_image_srcset
  • the_content
  • widget_text
  • style_loader_src
  • script_loader_src

The second pass is only applied to cached page, using our rocket_buffer filter hook. It will do the replacement for any CSS/JS file or image that is added on the page and not going through the previous hooks.