Issue with Fixed Content using CSS/ Dynamic Expressions in JS

Dec 8, 2011 at 12:38 AM

With latest AjaxMin below CSS is broken. (') single quote is converted to double quotes hence resulting in js error when compressed CSS is used in javascript file. This looks like regression because there is no issue with older version of ajaxmin.


* html .hts_pop #ht_content{    height:expression((this.childNodes.length && this.childNodes[0].offsetHeight > 272 ) ? '272px' : 'auto')}


Actual Minified CSS 


* html .hts_pop #ht_content{height:expression(this.childNodes.length&&this.childNodes[0].offsetHeight>272?"272px":"auto")}


Expected Minified CSS


* html .hts_pop #ht_content{height:expression(this.childNodes.length&&this.childNodes[0].offsetHeight>272?'272px':'auto')}



var _css = "* html .hts_pop #ht_content{height:expression(this.childNodes.length&&this.childNodes[0].offsetHeight>272?"272px":"auto")}";                <-----------throws error

Dec 8, 2011 at 12:51 AM

I'll get this fixed. I'm actually surprised it changed from single- to double-quotes.

Dec 8, 2011 at 1:02 AM

Oh, I see what's going on. I was surprised that a CSS string's delimiter was changed, but that isn't what's happening here. That is an expression function, so everything within it is JavaScript, and the JS parser is parsing and outputting the code within that function. So this issue is actually that the JS parser defaults to double-quote delimiters unless the string contains more double-quotes than single-quotes (in which case it will use single-quote delimiters). The solution would be to pass in the appropriate CodeSettings object to tell the JS minifier to not optimize string literals. And right now there is no mechanism to specify JS options when parsing CSS (it just uses the default settings).

One thing you can do in the short term is to turn off JavaScript minification for CSS code. If you are using the command-line executable, you can specify -expr:raw option. But that also means whitespace and other optimizations won't be taken out of the JavaScript inside CSS code. It would stop your script error, though, until I can add an option to minify the JS but not alter literals. More to come....

Dec 12, 2011 at 5:03 AM

This should be fixed with the 4.39 release. You won't need to use the -expr:raw switch anymore.

Dec 16, 2011 at 7:20 PM
Edited Dec 16, 2011 at 7:20 PM

Thanks Ron!