Enabling this option in “HTML Source CleanUp” within Asset CleanUp’s “Settings” will strip the comments that have been added by the theme & plugins between the HTML tags (basically valid comments).

It will not literally strip anything between <!-- and --> if they don’t qualify as valid HTML comments. For instance, in the following examples, nothing will be removed as they are not valid comments:

<div data-text="This is <!-- an example -->">Text here</div>
<script>var jsVariable = 'This is just <!-- an example--> of a text';</script>

What about the HTML comments that are added within the cached HTML files generated by caching plugins such as WP Rocket, WP Fastest Cache or Comet Cache?

Asset CleanUp is not altering the cached files that are generated by plugins. Instead, it cleanups everything before the HTML is cached. Some plugins are dynamically adding comments to the cached HTML, the moment is processed in /wp-content/advanced-cache.php. As some of these plugins change regularly and sometimes do changes to the HTML without even loading the WP environment (e.g. when an external non-WordPress PHP file created by a plugin is triggered), Asset CleanUp does not interfere with their caching. The best practice would be to follow their tips in order to remove the comments (if you want to), via the options that they provide.

For instance, WP Rocket provided documentation on how their “Performance optimized by WP Rocket” comment can be stripped here:
https://docs.wp-rocket.me/article/7-enabling-white-label

WP Fastest Cache, another popular caching plugin, offers the option to strip the powered by the comment by applying the following code at the top of wp-config.php (the root of the WordPress installation):

if (! defined('WPFC_REMOVE_FOOTER_COMMENT')) {
    define('WPFC_REMOVE_FOOTER_COMMENT', true);
}

if (! defined('WPFC_REMOVE_VIA_FOOTER_COMMENT')) {
    define('WPFC_REMOVE_VIA_FOOTER_COMMENT', true);
}

Was this post helpful?