Title: CDN und SRCSET
Last modified: August 30, 2016

---

# CDN und SRCSET

 *  [solemone](https://wordpress.org/support/users/solemone/)
 * (@solemone)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/cdn-und-srcset/)
 * Hi,
    I use the [RICG Responsive Images plugin](https://wordpress.org/plugins/ricg-responsive-images/)
   to add the srcset attribute to my images.
 * When I use a CDN with W3TC only the first image in the srcset-array is rewritten
   to the CDN URL. Example:
 * `<img srcset="http://cdndomain.com/300.jpg 300w, http://mydomain.com/400.jpg 
   400w, http://mydomain.com/600.jpg 600w," sizes="(min-width: 37.5rem) calc(50vw-
   1.75em), calc(100vw - 2em)" alt="Image">`
 * Is there a possibility to rewrite the image array in the cached files?
 * Thanks
    Ivo
 * [https://wordpress.org/plugins/w3-total-cache/](https://wordpress.org/plugins/w3-total-cache/)

Viewing 14 replies - 1 through 14 (of 14 total)

 *  [TerraConnect](https://wordpress.org/support/users/terraconnect/)
 * (@terraconnect)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6486985)
 * Up! Any news?
    It is crippling.
 * Thanks. TC
 *  [manuelmasia](https://wordpress.org/support/users/manuelmasia/)
 * (@manuelmasia)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487058)
 * Interested as well!
 *  [cLin](https://wordpress.org/support/users/clin/)
 * (@clin)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487062)
 * Looks like this is still a problem. Anyone have a fix?
 *  Thread Starter [solemone](https://wordpress.org/support/users/solemone/)
 * (@solemone)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487063)
 * You can use the CDN Linker in combination with W3TC
    [https://github.com/wmark/CDN-Linker](https://github.com/wmark/CDN-Linker)
 *  [JSSAggie](https://wordpress.org/support/users/jssaggie/)
 * (@jssaggie)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487064)
 * I posted the same problem here:
    [https://wordpress.org/support/topic/wordpress-44-srcset-for-responsive-images-not-referring-to-cache-image?replies=4](https://wordpress.org/support/topic/wordpress-44-srcset-for-responsive-images-not-referring-to-cache-image?replies=4)
 * No update from anyone.
 *  [ardalanme](https://wordpress.org/support/users/ardalanme/)
 * (@ardalanme)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487065)
 * Hey everyone,
    I came up with a quick fix. Feel free to implement it until the
   plugin author publishes an update.
 * In plugins/wp3-total-cache/lib/W3/Plugin/Cdn.php line 1008 change the following
   code:
 *     ```
       if (preg_match('~' . $domain_url_regexp . '~i', $baseurl)) {
                   $regexps[] = '~(["\'(])\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\')>]+)))~';
               } else {
                   $parsed = @parse_url($baseurl);
       ```
   
 * To:
 *     ```
       if (preg_match('~' . $domain_url_regexp . '~i', $baseurl)) {
                   $regexps[] = '~(["\'(])\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\')>]+)))~';
   
                   // This will correct up to 10 media urls within a html attribute (srcset for example)
                   for ( $i = 0; $i < 10; $i++ )
                       $regexps[] = '~([(, )"\'(])\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\')>]+)))~';
   
               } else {
                   $parsed = @parse_url($baseurl);
       ```
   
 *  [wigsyboy](https://wordpress.org/support/users/wigsyboy/)
 * (@wigsyboy)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487066)
 * thanks ardalanme, your fix works
 * [http://www.miapropertyboutique.com/](http://www.miapropertyboutique.com/)
 *  <img width=”244″ height=”163″ src=”[http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-244×163.jpg&#8221](http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-244×163.jpg&#8221);
   class=”attachment-property-thumb-image size-property-thumb-image wp-post-image”
   alt=”se vende bungalow en alicante golf” srcset=”[http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-300×200.jpg](http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-300×200.jpg)
   300w,[http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-768×512.jpg](http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-768×512.jpg)
   768w,[http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037.jpg](http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037.jpg)
   1024w,[http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-150×100.jpg](http://cdn4.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-150×100.jpg)
   150w,[http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-244×163.jpg](http://cdn5.miapropertyboutique.com/wp-content/uploads/2015/12/M80_5037-244×163.jpg)
   244w” sizes=”(max-width: 244px) 100vw, 244px” />
 *  [wigsyboy](https://wordpress.org/support/users/wigsyboy/)
 * (@wigsyboy)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487067)
 * just rememebr to deactivate and reactivate the W3TC plugin after making the change
 *  [M3](https://wordpress.org/support/users/emmtre/)
 * (@emmtre)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487068)
 * [@ardalanme](https://wordpress.org/support/users/ardalanme/) Many thanx for the
   fix. From my testing it looks like it’s working.
 *  [Jasper de Groot](https://wordpress.org/support/users/jaspermdegroot/)
 * (@jaspermdegroot)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487070)
 * Related thread [https://wordpress.org/support/topic/cdn-doesnt-rewrite-srcset-urls?replies=1#post-7448963](https://wordpress.org/support/topic/cdn-doesnt-rewrite-srcset-urls?replies=1#post-7448963)
 *  [awhig](https://wordpress.org/support/users/awhig/)
 * (@awhig)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487075)
 * This works for me! Thank you!
 *  [Ash](https://wordpress.org/support/users/ashmetry/)
 * (@ashmetry)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487076)
 * Worked. Thanks!
 *  [rmkahler](https://wordpress.org/support/users/rmkahler/)
 * (@rmkahler)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487092)
 * Does anyone have any idea if this issue has been fixed on W3TC’s side? I.e. W3TC
   can be used with Cloudfront without having to do the fix mentioned above?
 *  [Ashok](https://wordpress.org/support/users/bappidgreat/)
 * (@bappidgreat)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487093)
 * Hello rmkahler
 * I can confirm the changes are not added in the W3TC yet, so you still have to
   make the changes yourself. And if the changes are not added in next update, after
   updating you have to add it again.
 * Have a good day!
 * Cheers
    Ash

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘CDN und SRCSET’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

## Tags

 * [cdn](https://wordpress.org/support/topic-tag/cdn/)
 * [rewrite url](https://wordpress.org/support/topic-tag/rewrite-url/)
 * [srcset](https://wordpress.org/support/topic-tag/srcset/)

 * 14 replies
 * 13 participants
 * Last reply from: [Ashok](https://wordpress.org/support/users/bappidgreat/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/cdn-und-srcset/#post-6487093)
 * Status: not resolved