This project is read-only.


3 issues with the JavaScriptCompressor



I used the JavaScriptCompressor class and encountered the following three problems.
  1. The attribute "ContentType" is readonly. Shouldn't it be writable in case I am using another file extension than 'js' or 'css'?
  2. In contrast to the YUI compressor the special comment /! important comment / is retained but without the exclamation mark -> so a double minification would remove such comments.
  3. When setting the "LineBreakPosition" to a certain value (e.g. 2000) then the first line is 2000 or less characters long, but the following lines are getting longer and longer - this is probabely not intended.
Closed May 9, 2014 at 4:34 PM by freeranger
Nothing to do


freeranger wrote Apr 22, 2014 at 5:48 PM

  1. the content type has nothing to do with file extensions - it is the mime type of the content you are returning. This is text/css or text/javascript as appropriate to the compressor being used.
    You can pass files with whatever names you like into the compressor
  2. Why would you want to double-minify at all?
For both 2 and 3 - what version are you using, and can you send a sample exhibiting the exact behavior you are describing?


Volkmar wrote Apr 26, 2014 at 7:39 PM


First thanks for your answers but let me shortly explain why I come to this three points.
  1. ContentType - I read the documentation on '' and found the following description of the global option '--type':
--type js|css
  The type of compressor (JavaScript or CSS) is chosen based on the
  extension of the input file name (.js or .css) This option is required
  if no input file has been specified. Otherwise, this option is only
  required if the input file extension is neither 'js' nor 'css'.
That's why I expectet this property to be writeable.
  1. Special comments - the documentation on '' states the following about the handling of special comments:
The ! character itself is also preserved. This way you can safely double-minify the same file (probably by mistake). That also allows when reviewing the code (manually or with tools) to see ! and conclude that this comment is there intentionally, not because you forgot to minify the CSS.

To me this makes sense - hence preserving the ! charater seems to be the right way.
  1. LineBreakPosition - you should be able to reproduce the behavior descriped with any uncompressed version of jQuery and setting the LineBreakPosition to 2000.
I am using the following versions (info from the file properties):
 Size: 349.696 Bytes
 Size: 38.400 Bytes
Of course none of the points mentioned above is a show stopper - I am just a bit pedantic. Sorry ;-)

freeranger wrote May 9, 2014 at 4:34 PM


I am closing this issue because it is not an issue at all, for the following reasons:

ContentType - you are referring to the documentation for yahoo's java implementation of the compressor and how you run it to choose between js and css compression.
Our implementation produces compatible files but is not used in the same way - in particular it is split into separate css and js compressors.

Special comments - there is no problem with these as the following test passes:
        public void A_Special_Comment_Can_Be_Compressed_Multiple_Times()
            // Arrange
            const string source = @"/*!
                                    (c) Very Important Comment

            // Act
            var actual = target.Compress(target.Compress(target.Compress(source)));

            // Assert
            Assert.That(actual, Is.EqualTo(source));
Line breaks - again, there is no problem with these:
        public void LineBreaks_Are_Honoured_Where_Possible()
            // Arrange
            const string source = @"#foo
                                            position: relative;
                                    #bar {
                                            height: 310px;
                                            background: #c00 url(/image/home_bg.png) 0 100% repeat-x;
                                            z-index: 1000;
                                    #baz { 
                                    #buzz { 
            const string expected = "#foo{position:relative}\n" +
                                    "#bar{height:310px;background:#c00 url(/image/home_bg.png) 0 100% repeat-x;z-index:1000}\n" +
                                    "#baz{width:10}\n" +

            target.LineBreakPosition = 10;
            var actual = target.Compress(source);
            Assert.That(actual, Is.EqualTo(expected));
The linebreak is inserted after a closing '}' as close to the desired break size as possible

wrote May 9, 2014 at 4:34 PM