SquishIt
SquishIt copied to clipboard
SquishIt replacing javascript variables
(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 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.
(http://stackoverflow.com/questions/32552473/squishit-replacing-with-short)
This is minifier behavior, not squishit.
I think you might be able to work around it with the MS Minifier using something like this (http://stackoverflow.com/questions/5888580/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>()
Did you use the .MakeAllSafe method with the MS minifier? I'm wondering if that should be the default behavior going forward.
I plan to make YUI the default minification option as of v1.0 so that may make sense if we want to keep behavior consistent.