Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Johannes Pille, Pieter Goosen, cybmeta, birgire, anu Nov 12 at 15:13

This question appears to be off-topic. The users who voted to close gave these specific reasons:

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

Okay, the answer is pretty obvious. Let me explain by example:

  1. 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.

  2. 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:

    .expand-down {
        padding-left: 14px;
        background: url(/wp-content/themes/v7/img/right_arrow.png) left center no-repeat;
    }
    
    #twitter_bird {
        background: url(../themes/v7/img/tech-innovators/twitter_bird.png) no-repeat scroll left top transparent;
        width: 34px;
        float: left;
        height: 24px;
        margin: 9px 0 0 7px;
        display: block;
    }
    

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?!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.