javascriptc#minifysquishit

SquishIt replacing with short


I'm using 9.8.0 latest stable framework of SquishIt.

Problem with javascript minify. When it minify long variables like function(imReallyLong) to function(n)

This is ok for minify but only if you are not using eval()!

My method was:

Fire: function (jDto) {
    var sectionName = Enum.Parse(Enum.SectionID, jDto.SectionID);
    eval('Section.Init.' + sectionName + '(jDto)');
},

After minify:

Fire: function (n) {
    var t = Enum.Parse(Enum.SectionID, n.SectionID);
    eval("Section.Init."+t+"(jDto)")
},

The problem jDto variable. It is hard coded as string and SquishIt can't know it.

Is it possible to prevent changing variables option or something like that? Or more cool framework?

Thank you.


Solution

  • This is minifier behavior, not squishit.

    I think you might be able to work around it with the MS Minifier using something like this (Ajax Minifier (AjaxMin) - EvalTreatment for JavaScript?):

    .WithMinifier(new MsMinifier(new CodeSettings { EvalTreatment = EvalTreatment.MakeAllSafe }))
    

    There is an ignoreEval option for YUI minifier that looks like it allows functions calling eval to be compressed (https://github.com/BillyChan501/YUI-Compressor-.NET/blob/master/Projects/Yahoo.Yui.Compressor/Model%20Tests/JavaScriptCompressorTest.cs#L218-L256). So the example you have might "just work" using default YUI options for minification?

    .WithMinifier<YuiMinifier>()