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?
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:
Obviously, the minified function performs more than twice as fast.
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.
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/
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:
- The number of files that have to be loaded, especially if they're loaded from other domains.
- The size of images, both in terms of dimensions and of compression.
- Having your server Gzip large files; see https://css-tricks.com/the-difference-between-minification-and-gzipping/.
© 2022 - 2025 — McMap. All rights reserved.