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
Add a ment  | 

1 Answer 1

Reset to default 9

From: 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