How does W3 Total Cache Load Images In Stylesheet via CDN?

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.

Read More

It’s weird how W3TC does that. Does anyone know?

Related posts

Leave a Reply

1 comment

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