Is there some valid purpose to minifying before compressing? It seems highly unlikely that the gzipped file is smaller if it's minified first.
I ask because diagnosing production problems in minified code is substantially more difficult, and I'm wondering if people are subjecting themselves to that for no purpose.
Minifying strips out all comments, superfluous white space and shortens variable names. It thus reduces download time for your JavaScript files as they are (usually) a lot smaller in filesize. So, yes it does improve performance.
Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.
These characters include whitespaces, line breaks, comments, and block delimiters which are useful for us humans but unnecessary for machines. We minify the files of a website containing CSS, HTML, and Javascript code so your web browser can read them faster.
Despite being an excellent programming language, JavaScript impacts web pages by slowing them down. To regain space and improve your page load speed, you must minify the JavaScript code. The minified version of JavaScript code can reduce the file size by as much as 30–90%.
As for raw file size, here is a sample (jQuery 1.4.2):
$ curl http://code.jquery.com/jquery-1.4.2.js | gzip > jquery.gz
$ curl http://code.jquery.com/jquery-1.4.2.min.js | gzip > jquery-min.gz
$ ls -la jquery*
-rw-r--r-- 1 me staff 24545 Apr 7 12:02 jquery-min.gz
-rw-r--r-- 1 me staff 45978 Apr 7 12:02 jquery.gz
So the minified version is about half the size.
Yes, there is definately a benefit.
Minifying is a lossy compression whereas gzipping is lossless. Ergo, with minifying you remove unneeded data (like comments and long variablenames) which will always help to make your file smaller. Even with gzip there will still be a difference in most cases.
Example:
function foo(this_is_my_variable){
var this_is_my_other_variable = 0;
this_is_my_other_variable = this_is_my_other_variable + this_is_my_variable;
return this_is_my_other_variable;
}
That might be minified to:
function foo(a){
var b = 0;
b = b +a;
return b;
}
Or if the minifier is smart:
function foo(a){
return a;
}
All code gives the same results, but the size differs a lot.
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