Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SquishIt replacing javascript variables #320

Open
ErcinDedeoglu opened this issue Sep 13, 2015 · 2 comments
Open

SquishIt replacing javascript variables #320

ErcinDedeoglu opened this issue Sep 13, 2015 · 2 comments

Comments

@ErcinDedeoglu
Copy link

(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)

@AlexCuse
Copy link
Collaborator

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>()

@AlexCuse
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants