I have reports - no source available, I'm afraid - of a web application that doesn't work on devices using some mobile data networks, because the network operators are running a non-transparent proxy that is compressing images and minifying JavaScript, and the minification is actually breaking the code.
I'm curious as to whether anyone has an example (i.e. a code snippet plus a minification technique) whereby sloppy JS code combined with aggressive minification could actually change the meaning of the code? I suspect such a combination is possible but can't think of - or find - any examples. Anyone got a good example, or a proof to the contrary?
JavaScript Minification is the process of reducing the size of JavaScript files. To reduce the size, the comments, extra white spaces, and new line characters are removed from the script and the variable names are replaced with shorter variable names.
A semantic element clearly describes its meaning to both the browser and the developer. Examples of non-semantic elements: <div> and <span> - Tells nothing about its content. Examples of semantic elements: <form>, <table>, and <article> - Clearly defines its content. Semantic Elements in HTML
What can JavaScript do? JavaScript statements are commands to the browser JavaScript code is a sequence of statements JavaScript statements are separated with semicolon Multiple statement on one line is allowed JavaScript statements can be grouped together in code blocks You can break a code line after an operator or a comma.
Advantages of Minification As minification reduces the size of JS file it reduces the download time and the web page loads much faster. It reduces the bandwidth consumption of site. It improves the script execution time also.
consider the following code:
function DoStuff(thingA, ThingB){
var thingC = thingA + ThingB;
return thingC;
}
var stuffingC = eval("DoStuff(stuffingA, stuffingB)");
minifiers sometimes shorten variable or function names:
function DS(A, B){return A+B;}
var C= eval("DoStuff(stuffingA, stuffingB)");
In this case, your code would break because the eval'd string isn't changed to account for the changed name of your function.
this is a basic example, but this is often what happens: you have some sort of reflection or evaluation of a string variable that refers to a minified piece of code with the pre-minification name, but isn't changed to account for this minified nature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With