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?
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.
The process of minification reduces the readability of the code.
Minification of JavaScript files reduces payload and script parse time, resulting in faster page loads.
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.
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With