AO (or rather the HTML minifier used by AO) indeed keeps the linebreaks raphaelfabeni.
I see… that’s sad!
Anyways, Thank you! π
And keep the good work!
Well, you can hook into AO’s API (the autoptimize_html_after_minify filter) to remove those linebreaks. I think I have something like that floating around on one of my servers even π
Really? Interesting! π
I will take a look at it!
let me know if you need example code π
I was doing it right now! If you could send it to me here I’d love to compare!
Thanks π
hmm, couldn’t find the code I had in mind, but something like the following would likely do the trick;
add_filter( 'autoptimize_html_after_minify', 'remove_newlines');
function remove_newlines( $html_in ) {
return str_replace( array('\r', '\n'), ' ', $html_in );
}
I did almost the same!
add_filter( 'autoptimize_html_after_minify', function($content) {
$content = str_replace(array("\r", "\n"), '', $content);
return $content;
});
Thanks again for all the support!
π
Hey! π Just getting back to this: I used the code snippet you sent me.. but it seems is not working. The one that I wrote I got an error (Unexpected end of input). Probably because I have some JS inline in the page.
ah, my code had single-quotes around the elements in the array, but those should be double-quotes. but afraid the same problem will occur (JS linebreaks), so some more advanced technique will have to be used to exclude script-blocks, something like this;
add_filter( 'autoptimize_html_after_minify', 'remove_newlines');
function remove_newlines( $html_in ) {
$html_in = autoptimizeBase::replace_contents_with_marker_if_exists(
'SCRIPT',
'<script',
'#<(?:no)?script.*?<\/(?:no)?script>#is',
$html_in
);
$html_in = str_replace( array("\r", "\n"), ' ', $html_in );
$html_in = autoptimizeBase::restore_marked_content( 'SCRIPT', $html_in );
return $html_in;
}
Awesome! I will try it! Thanks for the quick reply!