Support » Plugin: Autoptimize » enable CDN for images referenced in the CSS.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Frank Goossens

    (@futtta)

    That seems like a bug (regression), I’ll look into that. Thanks for reporting!

    Kind regards,
    frank

    Plugin Author Frank Goossens

    (@futtta)

    So, could you open up /wp-content/plugins/autoptimize/classes/autoptimizeBase.php and on (or around) line 173 replace the existing url_replace_cdn-function with this;

    protected function url_replace_cdn($url) {
                    if (!empty($this->cdn_url)) {
                            // first allow API filter to take care of CDN replacement
                            $tmpurl = apply_filters( 'autoptimize_base_replace_cdn',$url);
                            if ($tmpurl === $url) {
                                    // secondly prepend domain-less absolute URL's
                                    if((substr($url,0,1)==='/')&&(substr($url,1,1)!=='/')) {
                                           $url=rtrim($this->cdn_url,'/').$url;
                                    } else {
                                            // three: replace full url's with scheme
                                            $tmp_url=str_replace(AUTOPTIMIZE_WP_SITE_URL,rtrim($this->cdn_url,'/'),$url);
                                            if ($tmp_url===$url) {
                                                    // last attempt: replace scheme-less URL's
                                                    $url=str_replace(preg_replace('/https?:/','',AUTOPTIMIZE_WP_SITE_URL),rtrim($this->cdn_url,'/'),$url);
                                            } else {
                                                    $url=$tmp_url;
                                            }
                                    }
                            } else {
                                    $url=$tmp_url;
                            }
                    }
                    return $url;
    }

    let me know how that works for you!

    frank

    I got it to work! 🙂

    It seems that the developer had chosen to use @import to include the parent CSS in stead of using wp_enqueue_style. Changing this made it work.

    Now, I don’t have the old code for the function that I replaced, so I can’t tell if it works with the old code too, but with your new code, and my edit in how the parent CSS is loaded, works.

    Bump to let you know that I updated my previous answer 🙂

    Plugin Author Frank Goossens

    (@futtta)

    thanks for the bump. the original version of the code would not have worked, because url_replace_cdn did not take scheme-less URL’s into account. i’ll be updating the code on “trunk” with some more improvements in cdn-handling (a.o. also apply CDN if “inline small images” is present for those files that cannot be inlined) and will ping you here if you can download that version.

    frank

    Thanks a bunch! 🙂 I will be looking forward for the update, and thanks for the quick update.

    It’s not a problem for me, and I know that it’s not the best practice code when people do it, but, do you think you could enable support for people who use the @inport in their CSS styles too? There is a great chance for someone sitting out there with that setup.

    That being said, don’t use too much time on it 😉 The code you would be supporting is not best practice 😉

    Plugin Author Frank Goossens

    (@futtta)

    Oh, but it should work with @imports just fine. I suppose it did not for you at first as you were seeing autoptimized CSS from cache (i.e. without CDN’ed URL’s), but by changing the way the parent CSS was loaded you invalidated the cache and you saw the fixed version.

    If you have the time to do so, you could switch back to the @import, empty your cache and confirm if it indeed works? 🙂

    frank

    Oh, it seems to work. Nice! 🙂 My bad, and good insight 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘enable CDN for images referenced in the CSS.’ is closed to new replies.