Thank you 🙂
What could be improved in AO’s HTML optimization?
Minify Html (plugins/minify-html-markup/) has a very useful feature, it removes trailing slashes and is very useful to W3C actual standards validations. It even compresses more the code.
$buffer = str_replace( ' />', '>', $buffer );
I think is very easy to introduce this feature in Autoptimize. Let me know if you do it.
-
This reply was modified 3 years, 5 months ago by
Pandasonic2.
ah, those trailing slashes, someone else asked about those as well. If you want I can provide you with a code snippet to make this happen in AO as well?
But I’ll put the feature on the backlog for later consideration 🙂
Yes, I’d like. It’s always better to reduce the number of plugins installed, so I’ll remove the other one. Thank you.
-
This reply was modified 3 years, 5 months ago by
Pandasonic2.
OK, this code snippet (untested!) should work;
add_filter( 'autoptimize_html_after_minify',
function( $html ) {
return str_replace( ' />', '>', $html );
}
);
I tried the code locally and seems to be ok. I only had to deactivate lazy loading in perfmatters and move to lazy load in autoptimize. At difference than minify html the snippet doesn’t change perfmatters code in images.
I added some other changes in html code to validate in W3C because WP in “class-wp-styles” and “class-wp-scripts” respectively adds “text/css” and “text/javascript”.
add_filter( ‘autoptimize_html_after_minify’,
function( $html ) {
return str_replace( ‘ />’, ‘>’, $html );
return str_replace( ‘type=\’text/javascript\”, ”, $html );
return str_replace( ‘type=\’text/css\”, ”, $html );
return str_replace( ‘/>’, ‘>’, $html );
}
);
-
This reply was modified 3 years, 5 months ago by
Pandasonic2.
once you return everything after it won’t get executed, so maybe use something like this instead?
add_filter( 'autoptimize_html_after_minify',
function( $html ) {
$html = str_replace( ' />', '>', $html );
$html = str_replace( ‘type=\’text/javascript\'', '', $html );
$html = str_replace( ‘type=\’text/css\'', '', $html );
return $html;
}
);