CSS Compression does not remove CSS Comments

Sep 20, 2011 at 6:34 PM


I am using the YUI Compression for .NET successfully, however CSS comments like so : 
/* XYZ */
are not being excluded from the CSS output file named StyleSheetFinal.css.   I am using CssCompressionType="BestOfBothWorlds" and have tried a few others.

Is this working for other folks?  What could be wrong with my CSS comments?
Sep 21, 2011 at 12:00 AM

Can you try doing it here: http://www.refresh-sf.com/yui/

if it works there, then there's a bug with the code I ported.

Sep 21, 2011 at 4:59 PM

Yes, it does work with the online version.  Comments are preserved for me still.  Here's a small snippet of my StyleSheetFinal.css with CSS comments in bold.:


div.DDNavigation img{position:relative;margin-top:0;padding:0 8px;border:none;background-color:#fff}div.DDNavigation a{color:#839ce7;text-decoration:none;background-color:#fff;padding-right:8px;top:-.2em;left:.25em}div.DDNavigation a:hover{color:#009;text-decoration:underline!important}/* Details VIEW/EDIT */ table.DDDetailsTable{background-color:#F7F7FF;border:solid 1px #dbddff;border-collapse:collapse;font:.85em Trebuchet MS,Arial,Helvetica;padding:3px,3px,3px,8px;color:#333;width:970px;vertical-align:middle}table.DDDetailsTable .DDSelected a:hover{color:#009;text-decoration:underline}table.DDDetailsTable a{color:#333;font-size:1em;text-decoration:none;padding:4px,4px,4px,4px}table.DDDetailsTable a:hover{color:#009;font-size:1em;text-decoration:underline!important}table.DDDetailsTable .td{padding:3px 3px 3px 8px;border:dotted 1px #dbddff;font-size:.95em;line-height:1.1em;font-family:Trebuchet MS,Arial,Helvetica;vertical-align:top}/* DDGridView/DDListView */ table.DDGridView,table.DDListView{width:940px;color:#000;border:solid 1px #dbddff;border-collapse:collapse;font:.85em Trebuchet MS,Arial,Helvetica;padding:3px,3px,3px,8px}

Sep 22, 2011 at 12:45 AM

awesome. so just to confirm, you've used that exact css, listed above and the css comments are not getting stripped. But when u do it with the online version, they are getting stripped.


if this is the case, can you also print out the code you are doing? is it programatically? or via command line with msbuild? if it's msbuild, can you also show me the xml file, etc so i can see all the 'arguments' you are setting, etc.


cheers :)

Sep 28, 2011 at 4:52 PM

I'm seeing the same issue, here but have found that it works the same as the online version if I set PreserveCssComments to "True" (I had it as "False" which is what I would have expected -I don't want to preserve the comments...).





Sep 28, 2011 at 6:32 PM

Thanks Tim, that's it.  I missed this because the PreserveCssComments  tag in the CompressorTask was missing in the documentation sample; it appears in the comments of the CompressorTask, but is not specified in the sample tag.  Thanks for help for pointing this out.

Oct 11, 2011 at 4:23 PM

Same here with Setting PreserveCssComments="true" actually removes comments, while PreserveCssComments="false" does not remove comments. Shouldn't that be reversed?

Jan 25, 2012 at 9:20 AM
Edited Jan 26, 2012 at 6:58 AM

This is in the code:

if (actionType == ActionType.Css)
	compressedContent = CssCompressor.Compress(originalContent,

but the compress method is declared as:

public static string Compress(string css, 
        	              int columnWidth,
                              CssCompressionType cssCompressionType,
                              bool removeComments);

following it through, removeComments true results in removing the comments so yes, it should be reversed....

Jan 26, 2012 at 6:06 PM

Fixed for next release: http://yuicompressor.codeplex.com/SourceControl/changeset/changes/74376