The 'Remove Comments' filter is enabled by specifying:
pagespeed EnableFilters remove_comments;
in the configuration file. To retain comments that have semantic reason to be
delivered to the browser, you may specify one more wildcard patterns
RetainComment directives. For example:
ModPagespeedRetainComment " google_ad_section*"
pagespeed RetainComment " google_ad_section*";
remove_comments filter eliminates HTML comments,
which are often used to document the code or to comment out
experiments. Note that this directive applies only to HTML files.
CSS comments are eliminated with the
eliminated with the
The filter reduces the transfer size of HTML files by removing most HTML
comments. Depending on the HTML file, this filter can significantly reduce the
number of bytes transmitted on the network. Also note that
RetainComment directive currently only applies to HTML files --
For example, if the HTML document looks like this:
<html> <body> <!-- Display the site logo here --> <img src="logo.png"> <!-- Now show the page contents --> <div>Some content here</div> <!-- Apply IE-specific CSS --> <!-- [if IE ]> <link href="iecss.css" rel="stylesheet" type="text/css"> <![endif]--> <!-- google_ad_section_end -- retained due to RetainComment directive --> </body> </html>
Then PageSpeed, with the above directives specified, will rewrite it into:
<html> <body> <img src="logo.png"> <div>Some content here</div> <!-- [if IE ]> <link href="iecss.css" rel="stylesheet" type="text/css"> <![endif]--> <!-- google_ad_section_end -- retained due to RetainComment directive --> </body> </html>
You can see the filter in action at
www.modpagespeed.com on this
The "Remove Comments" filter is aware of Internet Explorer conditional comments and does not remove them.