Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    I would not worry too much about a 29 Byte reduction, but if you do have a look at this thread which discusses why this can happen (“important” comments containing license info) and what you can do about it ??

    hope this clarifies,
    frank

    Hi Mr Browser,

    i am responding here because you write me via email and my contact form;)
    So i think that is not really a problem.

    You can use the helper file and the filter like this with str_replace and preg_replace to get these 29 Bytes ?? This should be normally not needed spaces and line breaks and comments.

    add_filter('autoptimize_js_after_minify','your_ao_override_js_after_minify',10,1);
    function your_ao_override_js_after_minify($jsIn) {
    #$jsOut = preg_replace("your code here", "", $jsIn);
    #$jsOut = str_replace(array("replace this", "and this", "and this"), 'with this', $jsOut);
    
    #comments in js files:
    $tag1 = '\/\*!'; //starting term
    $tag2 = '\*\/'; //end term
    $jsOut = preg_replace("#".$tag1.".*".$tag2."#Uis", "", $jsIn);
    
    #empty lines:
    $jsOut = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","", $jsOut);
    
    #line breaks, be careful!!:
    $jsOut = str_replace(array("\r\n", "\r", "\n"), '', $jsOut);
    	
    return $jsOut;
    }

    If all js-code is fine (all “;” are set correctly), this will work. If not, this could break the site.
    Just test it;)

    Best regards,
    Harry

    Thread Starter Mr_Browser

    (@mrbrowser)

    Hello again,

    Yeeees…works!! problem solved!
    Thank you, Harry Milatz and Optimizing Matters for solving this problem.

    one question:
    Does this code need to change after updating the Autoptimize plugin?

    – good luck!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no, the code can remain as is even when AO gets updated @mrbrowser ??

    and thanks for the explanation @harry-milatz !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Minify JavaScript’ is closed to new replies.