Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does minification work and does it affect angular nested objects?

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.

like image 324
user2167582 Avatar asked Jun 24 '13 17:06

user2167582


People also ask

How does JavaScript minification work?

How Minification Works. Minification works by analyzing and rewriting the text-based parts of a website to reduce its overall file size. Minification extends to scripts, style sheets, and other components that the web browser uses to render the site. Minification is performed on the web server before a response is sent ...

Does Uglify improve performance?

Uglification improves performance while reducing readability. Encryption: This is the process of translating data, called plain data, into encoded data. This encrypted, or encoded, data is known as ciphertext, and needs a secret key in order to decrypt it.

What is minification in angular?

Minification: In minification process following things are done within the js file to reduce the size of the js file for faster downloading. It removes all the white spaces within the file. It removes all the unwanted variables within the file. It converts all the big variable names to the smaller variable names.

What is the purpose of minification?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.


1 Answers

From: http://en.wikipedia.org/wiki/Minification_(programming)

Minification (also minimisation or minimization), in computer 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 compressor 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 compression rate by dropping certain compatibility requirements but I've found the resulting code to be very unstable so I don't think we're quite there yet :)

like image 186
Halcyon Avatar answered Sep 19 '22 20:09

Halcyon