Does minified javascript improve performance?

Minifying improves performance for your page overall by decreasing the load time (even if only slightly).

Neither minifying nor obfuscating alter execution time by any perceivable amount for the vast majority of javascript code out there.

I do recommend minifying for those reasons and more. Minifying multiple scripts together (like jQuery and it's plugins) can yield even greater savings.

Edit: As pointed out, on constrained devices and/or with very large codebases minifying could yield a noticeable result.


Minification

Minification does improve performance for two reasons:

  • Reduced file-size (because it removes comments and unnecessary white-spaces), so your script loads faster. Even if it is embedded into the <head>.

  • It is parsed faster, since comments and white-spaces don't have to explicitly ignored (since they're not there).

Combining

I've written quite a few HTML/JS AIR apps, and from personal experience, combining files won't make a difference. In fact, it's good practice to separate script based on certain criteria (classes, global functions, SQL functions etc). Helps keep them organised when the project becomes too big.

Obfuscation

Obfuscating is usually a combination of minification and renaming variables. It involves using eval to blow up the code again. This reduces performance for obvious reasons, but it depends on the size of your code.

I'd suggest running tests to understand this best for your specific situation.

[Edited to include special consideration for AIR apps]


Everyone here already talked about minifying but nobody talked about the 2nd part of your question - combining. This will definitely improve performance, probably even more than minifying.

Multiple files require multiple HTTP requests, so when you put them all into one file, only 1 request is needed. This is important for 2 reasons:

  • each individual HTTP request may take longer to load for various routing reasons, and 1 file will potentially delay your whole application.
  • browsers and other clients have a max limit of files they are allowed to download concurrently from a single domain. Depending on the number of files in your application, this may mean the client queuing them up, thus making the load even longer.

Also, besides minifying and combining, you have to absolutely make sure you have some sort of server side compression enabled. This can save you 90% or even more in the amount of bytes transferred, depending on the files.

You can read more about compression (gzip, deflate) here: http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/.

Tags:

Javascript