Quantcast
Viewing all articles
Browse latest Browse all 19296

Chad Huntley on "[Plugin: W3 Total Cache] CDN to Local Fallback"

Ended up coming up with a javascript solution for myself:

$(window).load(function() {
    $('img').each(function() {
        if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
            var source = this.src;
            this.src = source.replace(document.location.protocol + '://cdn.',document.location.protocol + '://');
        }
    });
});

This only works if your domain is non-www, and your cdn is formatted as "cdn.mydomain.com". This looks through all images, checks if the CDN version loaded, if not, falls back to mydomain.com. Now I can turn down the Amazon S3 sync to once a day, and there are no noticeable performance issues.


Viewing all articles
Browse latest Browse all 19296

Trending Articles