WordPress.org

Ready to get started?Download WordPress

Forums

Autoptimize
[resolved] Data URIs (6 posts)

  1. will.blaschko
    Member
    Posted 1 year ago #

    When I enter bare data uris in my scss file (without quotes), the whole line is stripped from the final css file, example below:

    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iNjAiIGhlaWdodD0iMzAiPgo8ZGVmcz4KPHJlY3QgaWQ9InIiIHdpZHRoPSIzMCIgaGVpZ2h0PSIxNSIgZmlsbD0iI2JiMDg1ZiIgc3Ryb2tlLXdpZHRoPSIyLjUiIHN0cm9rZT0iIzdhMDU0ZCI+PC9yZWN0Pgo8ZyBpZD0icCI+Cjx1c2UgeGxpbms6aHJlZj0iI3IiPjwvdXNlPgo8dXNlIHk9IjE1IiB4bGluazpocmVmPSIjciI+PC91c2U+Cjx1c2UgeT0iMzAiIHhsaW5rOmhyZWY9IiNyIj48L3VzZT4KPHVzZSB5PSI0NSIgeGxpbms6aHJlZj0iI3IiPjwvdXNlPgo8L2c+CjwvZGVmcz4KPHVzZSB4bGluazpocmVmPSIjcCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCAtMjUpIHNrZXdZKDQwKSI+PC91c2U+Cjx1c2UgeGxpbms6aHJlZj0iI3AiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDMwIDApIHNrZXdZKC00MCkiPjwvdXNlPgo8L3N2Zz4=);

    When I enter it with quotes, it stays intact, but then is not rendered correctly by the browser--it looks for a relative path. When I inject it into the CSS using Chrome's inspect, it shows up as it should.

    This happens with any Data URIs that I try to enter manually, your auto-inserted ones work perfectly.

    Thanks for any help you can give!

    http://wordpress.org/extend/plugins/autoptimize/

  2. futtta
    Member
    Plugin Author

    Posted 1 year ago #

    that sure looks like a bug Will, I'll look into this for the next release. thanks for the input!

  3. futtta
    Member
    Plugin Author

    Posted 1 year ago #

    OK, I think I've nailed this one.

    Can you open up wp-content/plugins/autoptimize/classes/autoptimizeStyles.php and on (or around) line 193 replace

    if($this->datauris == true && function_exists('base64_encode') && preg_match_all('#(background[^;}]*url\((.*)\)[^;}]*)(?:;|$|})#Usm',$code,$matches))

    with

    if($this->datauris == true && function_exists('base64_encode') && preg_match_all('#(background[^;}]*url\((?!data)(.*)\)[^;}]*)(?:;|$|})#Usm',$code,$matches))

    and in the same file somewhere around line 333 replace

    if(preg_match_all('#url?\((.*)\)#Usi',$code,$matches))

    with

    if(preg_match_all('#url?\((?!data)(.*)\)#Usi',$code,$matches))

    Clean your Autoptimize cache and it will (probably) work.

  4. futtta
    Member
    Plugin Author

    Posted 1 year ago #

    Even easier; I've applied a.o. these bugfixes to the development version of Autoptimize, which you can download here. Maybe you can give it a spin to see if it fixes your problems? Looking forward to your feedback!

  5. will.blaschko
    Member
    Posted 1 year ago #

    Looks good!

  6. futtta
    Member
    Plugin Author

    Posted 1 year ago #

    thanks for the feedback!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.