Gzip与minify [英] Gzip versus minify

查看:335
本文介绍了Gzip与minify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ p

我会把这个人称为X。

我有一个热烈的讨论,有关缩减Javascript和CSS的人喜欢使用Gzip。 >

X表示Gzip已经缩小了代码,因为它会压缩你的文件。



我不同意。 Zip是缩小文件大小的无损方法。无损意味着原始的必须完全恢复,意味着信息必须存储以能够恢复空格,不需要的字符,注释代码和一切。这需要更多的空间,因为必须压缩更多的空间。



我没有测试方法,但我相信这个代码的Gzip:

  .a1 {
background-color:#FFFFFF;
padding:40px 40px 40px 40px;
}

仍然会大于此代码的Gzip:

  .a1 {body:background-color:#FFF; padding:40px} 

有没有人可以证明这是正确的或错误的。
请不要说这是正确的,因为这是我一直使用的。 / p>

我在这里要求科学证明。

解决方案

测试。我把你的js,把它们放在不同的文件,并运行gzip -9对他们。这是结果。这是在运行Cygwin和gzip 1.3.12的WinXP机器上完成的。

  -rwx ------ 1 xxxxxxxx mkgroup -ld 88 Apr 30 09:17 expanded.js.gz 

-rwx ------ 1 xxxxxxxx mkgroup-ld 81 Apr 30 09:18 minified.js.gz

这里是使用真实世界JS示例的进一步测试。源文件为common.js原始文件大小为73134字节。

  -rwxrwxrwx 1 xxxxxxxx mkgroup-ld 73134 Apr 13 11:41 common.js 

缩小档案:

  -rwxr-xr-x 1 xxxxxxxx mkgroup-ld 26232 10:39 common-min.js 

原始文件gzipped with -9 option如上):

  -rwxrwxrwx 1 xxxxxxxx mkgroup-ld 12402 Apr 13 11:41 common.js.gz 

使用-9选项(与上述相同的版本)gzip压缩的缩小档案:

  -rwxr-xr-x 1 xxxxxxxx mkgroup-ld 5608 Apr 30 10:39 common-min.js.gz 

正如你所看到的,各种方法之间有明确的区别。最好的办法是缩小和压缩它们。


I had a somewhat lively discussion the other day about minifying Javascript and CSS versus someone who prefers using Gzip.

I'll call this person X.

X said that Gzip allready minifies the code, since it zips your files.

I disagree. Zip is a lossless method of shrinking filesize. Lossless means the original must be restored perfectly, meaning info must be stored to be able to restore the spaces, the un-needed characters, commented code and everything else. That takes up more space, since more must be compressed.

I have no method of testing, but I believe that the Gzip of this code:

.a1 {
    background-color:#FFFFFF;
    padding: 40px 40px 40px 40px;
}

Will still be bigger than the Gzip of this code:

.a1{body:background-color:#FFF;padding:40px}

Is there anybody who can prove this right or wrong.
And please don't come saying "It's right because that's what I've always used".

I am asking for scientific proof here.

解决方案

Very simple to test. I took your js, put them in different files and ran gzip -9 on them. Here's the result. This was done on a WinXP machine running Cygwin and gzip 1.3.12.

-rwx------  1 xxxxxxxx mkgroup-l-d     88 Apr 30 09:17 expanded.js.gz

-rwx------  1 xxxxxxxx mkgroup-l-d     81 Apr 30 09:18 minified.js.gz

Here's a further test using a real-world JS example. The source file is "common.js" The original file size is 73134 bytes. Minified, it came to 26232 bytes.

Original file:

-rwxrwxrwx 1 xxxxxxxx mkgroup-l-d 73134 Apr 13 11:41 common.js

Minified file:

-rwxr-xr-x 1 xxxxxxxx mkgroup-l-d 26232 Apr 30 10:39 common-min.js

Original file gzipped with -9 option (same version as above):

-rwxrwxrwx 1 xxxxxxxx mkgroup-l-d 12402 Apr 13 11:41 common.js.gz

Minified file gzipped with -9 option (same version as above):

-rwxr-xr-x 1 xxxxxxxx mkgroup-l-d  5608 Apr 30 10:39 common-min.js.gz

As you can see, there is a definite difference between the various methods. The best bet is to both minify as well as gzip them.

这篇关于Gzip与minify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆