What is an example of JavaScript code whose semantics will be changed by mini-coding?

I have reports - I'm not afraid of a source that does not work on devices using some mobile data networks, as network operators work with an opaque proxy server that compresses images and reduces JavaScript, and minimizing actually breaks the code.

I am curious if anyone has an example (i.e. a code snippet plus a minimization method), as a result of which sloppy JS code combined with aggressive boost can really change the meaning of the code? I suspect that such a combination is possible, but cannot come up with or find any examples. Has anyone got a good example or proof to the contrary?

+7
javascript minify cellular-network
source share
1 answer

consider the following code:

function DoStuff(thingA, ThingB){ var thingC = thingA + ThingB; return thingC; } var stuffingC = eval("DoStuff(stuffingA, stuffingB)"); 

minifiers sometimes abbreviate variable or function names:

 function DS(A, B){return A+B;} var C= eval("DoStuff(stuffingA, stuffingB)"); 

In this case, your code will be broken because the string eval'd will not be changed for the account for the changed name of your function.

this is a basic example, but often it happens: you have some kind of reflection or evaluation of a string variable that refers to the reduced part of the code with the name of the preliminary evaluation, but does not change to the account for this mineralized character.

+6
source share

All Articles