W3 Total Cache uses all the PHP / WordPress API trickery at hand to make sure all static content (CSS, JS, Images, etc.) is served from the CDN URL.
But how does it make sure that even the images referenced in my CSS/stylesheet file are also served from the CDN URL? I checked my CSS file, the path to the images hasn’t changed.
It’s weird how W3TC does that. Does anyone know?
Okay, the answer is pretty obvious. Let me explain by example:
W3 Total Cache makes sure that all the primary static contents on a web page (i.e. ones directly referenced in the source of the web page) are loaded via the CDN URL.
So, lets say, W3TC serves the blog’s stylesheet from
cdn.example.com/wp-content/themes/MY-THEME/style.css
and the stylesheet contains this piece of code:Since the CSS file has relative references to images’ locations. So, the browser simply serves them from the same domain as the domain the one the stylesheet is served from. How did I forget this simple thing?!