Writing JavaScript to minimize and optimize

By optimization, I mean, for example, the choice between using the base loop forand Array.prototype.forEach()on the basis of which the implementation seems to be accelerated when browsers, etc. (And in some cases, this can extend to micro-optimization, which they can be dangerous .)

Here is an example of what could be called "write to minimize":

if(foo === bar) {
    return true;
} else {
   return false;
}

// writing the following instead, which reduces size by a few bytes

return foo===bar; //will return true or false, depending on what the statement evaluates to

Some may argue that using this expression is if elsea bit readable at first glance, but I would say that the second way of writing it is best suited.

As for minimization, as I understand it, the big goal is to reduce server response time.

, ""?

Edit
, " ".

+4
1

. minifier YUI.

. . A minifier . - " " , .

+8

Source: https://habr.com/ru/post/1526635/


All Articles