Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any point to JavaScript minification if you have compression turned on?

If your website has deflate/zip compression enabled is there any point to JavaScript minification?

My theory is that the difference between a compressed minified JavaScript file and a compressed unminified JavaScript file is negligible.

There are very few browsers left out there that don't support compression. I would imagine that some bots (spiders) might not support compression (I know of at least one) but they are unlikely to be "interested" in your JavaScript as they are unlikely to be executing JS and so shouldn't be downloading it.

like image 818
Guy Avatar asked Jul 13 '10 16:07

Guy


People also ask

Does minification 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.

Should you minify your JS?

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.

Does minification reduce parse time?

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

Does gzip remove whitespace?

gzip collapses all that whitespace to very small amounts of info.


1 Answers

Let's just test it. I used jQuery 1.4.2 and gzip (without flags; -9 does not seem to make a significant difference) to get the following numbers.

  • Development: 163,855 bytes
  • Development, compressed: 45,994 bytes
  • Minified: 72,174 bytes
  • Minified, compressed: 24,565 bytes

So, in this particular case, minification makes the file nearly twice as small. Admittedly, the development release is full of comments. Let's strip those out, and see what happens:

  • Stripped: 131,155 bytes
  • Stripped, compressed: 32,914 bytes

That's still significantly larger than the minified version.

like image 170
Thomas Avatar answered Oct 16 '22 07:10

Thomas