Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 828
user584263 Avatar asked Feb 13 '15 06:02

user584263


People also ask

Does CSS minification increase page performance?

By stripping unnecessary data from the CSS code, minification helps the browser download and process these files faster, increasing page performance and improving user experience.

Which of these is a disadvantage of minification?

The process of minification reduces the readability of the code.

Does minification reduce parse time?

Minification of JavaScript files reduces payload and script parse time, resulting in faster page loads.

Is Minifying CSS worth it?

It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.


3 Answers

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/

like image 198
amarprabhu Avatar answered Oct 19 '22 01:10

amarprabhu


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.

like image 22
le_m Avatar answered Oct 19 '22 02:10

le_m


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.

like image 1
Jean-Baptiste Yunès Avatar answered Oct 19 '22 00:10

Jean-Baptiste Yunès