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

    (@futtta)

    well, you could disable the stock HTML optimization and do your own thing using the new autoptimize_html_after_minify filter to alter the HTML yourself?

    happy new year to you too!
    frank

    Thread Starter cluster666

    (@cluster666)

    could you please give me a sample w/ what I have to change to add breaks for HTML optimizing?
    I also need to keep the <![CDATA]]> tags in source.

    Regards
    Ralph

    Plugin Author Frank Goossens

    (@futtta)

    Well, taking into account that HTML optimization typically removes whitespace, linebreaks and comments, what would you want to do? just remove whitespace?

    Thread Starter cluster666

    (@cluster666)

    yep, whitespace removal but HTML should be visable line by line currently the html optimizer shows a one line source …
    would it be possible?

    Plugin Author Frank Goossens

    (@futtta)

    hmmm, something like

    add_filter('autoptimize_html_after_minify','cluster_html_minify',10,1);
    function cluster_html_minify($in) {
         $out=preg_replace('/^\s+|\s+$/m', '', $in);
         return $out;
    }

    If you disable HTML optimization, this should remove whitespace at the beginning or end of each line.

    Do be ware though; this is not tested at all, but just an simple example based on the regular expression found in this stackoverflow answer.

    hope this helps,
    frank

    Thread Starter cluster666

    (@cluster666)

    thank you, looks very good ??
    if I disable the HTML from backend I have to use that in /theme/functions.php right?

    ## edit ##
    the minified inline css do not line break at the end

    </style><title>123456</titke>

    any way to add a break only after </style>

    Ralph

    Plugin Author Frank Goossens

    (@futtta)

    in functions.php is OK, but if not in a child theme you’ll loose these changes when a theme update gets applied.

    regarding the line break after </style>; you could do a str_replace on $out, replacing “</style>” with “</style>\r\n”?

    frank

    Thread Starter cluster666

    (@cluster666)

    thanks Frank, it seems to work – except the </script> part for $out3, did not add the break …
    I’m doing something wrong here?

    add_filter(‘autoptimize_html_after_minify’,’cluster_html_minify’,10,1);
    function cluster_html_minify($in) {

    $out0 = preg_replace(‘/^\s+|\s+$/m’, ”, $in);
    $out1 = str_replace(“</style>”, “</style>\r\n”, $out0);
    $out2 = str_replace(“</title>”, “</title>\r\n”, $out1);
    $out3 = str_replace(“</script>”, “</script>\r\n”, $out2);
    $output = str_replace($out0, $out1, $out2, $out3);

    return $output;
    }

    Plugin Author Frank Goossens

    (@futtta)

    well, this line

    $output = str_replace($out0, $out1, $out2, $out3);

    doesn’t really make sense. remove it and do

    return $out3

    instead of

    return $output

    frank

    Thread Starter cluster666

    (@cluster666)

    thank you, it looks much better now ??
    a last question, can Autoptimize move java script snippets added by a plugin into the footer too?
    fex:

    <script type=”application/ld+json”>
    </script>
    and
    <script type=”text/javascript”>
    </script>

    Plugin Author Frank Goossens

    (@futtta)

    ld+json is intentionally left in place. is it not real javascript and will not impact performance (and aggregating it broke some stuff badly).

    text/javascript-snippets will by default be aggregated & minified, except if you exclude those in your config off course.

    frank

    Thread Starter cluster666

    (@cluster666)

    OK, I understand, but there is one script left in header which is not moved into the footer:

    <script type=”text/javascript”>
    var bhittani_plugin_kksr_js = {“nonce”:”1e5464eae6″,”grs”:true,”ajaxurl”:”https:\/\/www.mydomain.tld\/wp-admin\/admin-ajax.php”,”func”:”kksr_ajax”,”msg”:”Rate this post”,”fuelspeed”:400,”thankyou”:”Thank you for your vote”,”error_msg”:”An error occurred”,”tooltip”:”0″,”tooltips”:[{“tip”:””,”color”:”#ffffff”},{“tip”:””,”color”:”#ffffff”},{“tip”:””,”color”:”#ffffff”},{“tip”:””,”color”:”#ffffff”},{“tip”:””,”color”:”#ffffff”}]};
    </script>

    Plugin Author Frank Goossens

    (@futtta)

    ah, I see; scripts that have “nonce” in them (or post_id, for example) are excluded by default, as those will explode your cache (as the nonce can change with every page load).

    frank

    Thread Starter cluster666

    (@cluster666)

    ugh, currently they are placed between my hreflang tags …
    is there any way to move them in last order before </head> ?
    Regards, Ralph

    Plugin Author Frank Goossens

    (@futtta)

    afraid not (yet, anyway).

    frank

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘custom layout HTML’ is closed to new replies.