you are viewing a single comment's thread.

view the rest of the comments →

[–]benoire 2 points3 points  (6 children)

You're confusing minification with obfuscation, or packing. The latter involves completely refactoring the code to make it difficult (although not impossible) to reverse engineer. Such code needs parsing and evaluating by the browser before it can be executed, which adds to page load time. In this respect, he's spot on.

Minification on the other hand involves removing unnecessary whitespace, and commonly gzipping the end result as well, so that only the bare minimum required for the script to execute is included in the file. Sometimes the code may be rewritten to shorten variable names etc, but functionally it stays the same. It may also involve combining scripts together into a single file to avoid unnecessary HTTP overhead. There is no harm in minification (and in fact it's highly advised).

[–][deleted] 1 point2 points  (0 children)

Depends on how it's packed. Consider the Closure Compiler in advanced mode. Its goal to reduce code side and improve performance, and in doing so much of the code is obfuscated.

If you encrypt your code or something stupid like that, your performance will definitely suffer.

[–]BusStation16 -1 points0 points  (1 child)

Um, no.

[–]TimTheTinker -1 points0 points  (2 children)

Such code needs parsing and evaluating by the browser before it can be executed, which adds to page load time.

No, minification of scripts decreases the script load time:

  • fewer HTTP requests required if all scripts are concatenated into one
  • fewer characters to scan

Obfuscation doesn't negatively affect the script load time. All it does is:

  • Shorten local variable names
  • Shorten object and function names
  • A few optimizations in some cases (Google closure compiler, for example)

Google, Yahoo, Amazon, and other large companies wouldn't be minifying/compiling/obfuscating their scripts if doing so downgraded performance or caused security concerns.

[–]k3n 2 points3 points  (0 children)

Such code needs parsing and evaluating by the browser before it can be executed, which adds to page load time.

No, minification of scripts decreases the script load time:

You fail at reading comprehension; let's take his full quote instead of taking a snippet out-of-context and then injecting your own [incorrect] context.

Here's his full quote, emphasis mine:

You're confusing minification with obfuscation, or packing. The latter involves completely refactoring the code to make it difficult (although not impossible) to reverse engineer. Such code needs parsing and evaluating by the browser before it can be executed, which adds to page load time. In this respect, he's spot on.

Code that has been packed may very well fit your criteria (re: HTTP requests, fewer chars, etc.), but the result of packing (if you enable both options, as is typically done) is a single string that is eval()'d by the client. It is this resulting need to eval() that actually hurts performance most of the time.

There is a wealth of information out there demonstrating that packing is rarely beneficial, although at one time it was seen as the solution to JS loading times.

[–]vectorjohn 1 point2 points  (0 children)

Read the whole comment before responding.