Does minification improve performance?
Asked Answered
A

4

11

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

Anissaanita answered 13/2, 2015 at 6:29 Comment(1)
Minification does slightly improve performance, given the fact that the parser doesn't have to eat all that whitespace and comments, but it's not intended to, its main goal is to improve download speeds, which can be significant depending on your application's size.Tripoli
I
8

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.

Impi answered 1/7, 2016 at 0:21 Comment(0)
M
1

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.

Mantua answered 13/2, 2015 at 6:34 Comment(0)
F
1

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/

Faus answered 13/2, 2015 at 6:39 Comment(0)
K
0

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/.
Karisa answered 22/6, 2021 at 22:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.