user584263
user584263

Reputation: 385

Does minification improve performance?

I have minified my Javascript and CSS files using uglifyJS and the file size on disk has decreased considerably. But on checking the total time for resources loaded in network tab, using Chrome Developer tools, I find there is no difference. So does minification really improve performance? If yes how do I measure it?

enter image description here

Upvotes: 11

Views: 4596

Answers (4)

With the modern bandwidths, minification doesn't make any significant difference in total download time, as your own data show. And even in rendering time. What can make a significant difference in total download time are:

  1. The number of files that have to be loaded, especially if they're loaded from other domains.
  2. The size of images, both in terms of dimensions and of compression.
  3. Having your server Gzip large files; see https://css-tricks.com/the-difference-between-minification-and-gzipping/.

Upvotes: 0

le_m
le_m

Reputation: 20238

Minification can improve performance, depending on your JavaScript engine.

For example, Chrome's V8 optimizing compiler automatically inlines functions less than 600 characters long - including whitespace and comments.

Let's say we have a function which is more than 600 characters long:

function f() {
  // A long comment... bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  return 1;
}

Minification reduces this to function f(){return 1}.

If we now call both variants n times and compare the performance of the raw and the minified function, we get the following result:

Raw vs minified performance

Obviously, the minified function performs more than twice as fast.

Upvotes: 8

amarprabhu
amarprabhu

Reputation: 350

Minification does not improve execution time.

It however reduces the load time and the number of HTTP requests required by a substantial margin.

http://www.nczonline.net/blog/2009/07/07/javascript-minification-compression-and-performance/

Upvotes: 1

Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36431

It improves only the size of the JS, so its loading, but nothing else. MinifyJS is probably now not so useful; except if you have a lot of JS scripts to load for your pages. For example, if you use some JS framework or library then it is better to use their minified version, but for your own single script it may not be so interesting.

Upvotes: 1

Related Questions