admin管理员组文章数量:1295856
How does minification handle $scope.obj.subObj = { key: val ...};
from what I understand the last to use variable stays unchanged,
but if I were to have html element
<div>{{obj.subObj.key}}</div>
would the result of minify shorten the code to a.b.c.key? forgive me for asking in amateur fashion, but I'm trying to understand how javascript minification works.
How does minification handle $scope.obj.subObj = { key: val ...};
from what I understand the last to use variable stays unchanged,
but if I were to have html element
<div>{{obj.subObj.key}}</div>
would the result of minify shorten the code to a.b.c.key? forgive me for asking in amateur fashion, but I'm trying to understand how javascript minification works.
Share Improve this question edited Apr 18, 2018 at 17:39 user2167582 asked Jun 24, 2013 at 17:13 user2167582user2167582 6,38816 gold badges70 silver badges132 bronze badges 2- A decent minifier will not shorten public properties that are used elsewhere. Which one are you using? – Bergi Commented Jun 24, 2013 at 17:16
- Which tool do you use for minification? Some tools press the interfaces, some - don't. For instance, YUI Compressor won't change names of global variables and their contents - only function argument and local variable names will be minified. You can use it safely. – Egor Nepomnyaschih Commented Jun 24, 2013 at 17:18
1 Answer
Reset to default 9From: http://en.wikipedia/wiki/Minification_(programming)
Minification (also minimisation or minimization), in puter programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code, without changing its functionality.
So, if the minifier is able to detect that it can safely rewrite $scope.obj.subObj
to a.b.c
it will.
As a rule of thumb though, any variable that is from the global scope, like document
, window
or jQuery
will not be minified because other code (outside of the scope of this file) might depend on it.
The next step up from minifying is using a pressor like Google Closure Compiler or Yahoo's YUI Compressor. These programs are typically more powerful minifiers. They can replace a function call by an in-line function for instance or change a certain method by a shorter or faster method. This requires a lot of knowledge about JavaScript and performance optimizations.
You can crank up the pression rate by dropping certain patibility requirements but I've found the resulting code to be very unstable so I don't think we're quite there yet :)
本文标签: javascriptHow does minification work and does it affect angular nested objectsStack Overflow
版权声明:本文标题:javascript - How does minification work and does it affect angular nested objects? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618999a2388697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论