我正在尝试使用 apache deflate 模块压缩从我的应用程序发送的 excel 电子表格。我已将以下行添加到我的启用站点的文件中:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/excel
但是似乎是让响应数据变大了???
使用 firebug,在没有模块的情况下,我从应用程序下载了 xls 电子表格,它下载了 100Kb 的数据,文件系统上的文件大小也如预期的那样为 100Kb。如上所述启用 deflate 模块并重复该过程后,下载的数据量为 295Kb??但是一旦保存在文件系统上,文件仍然只有 100Kb。
作为实验,我手动 gzip 了保存的 xls 文件并将其压缩为 20Kb。
我在这里做错了什么?
使用 deflate(Firebug 输出):
200 OK xxxxxxx.co.za 293 KB
4.43s
ParamsHeadersPostPutResponseCacheHTML
Response Headers
Date Tue, 03 Nov 2009 13:01:43 GMT
Server Apache/2.2.4 (Ubuntu) mod_jk/1.2.23 PHP/5.2.3-1ubuntu6.4 mod_ssl/2.2.4 OpenSSL/0.9.8e
Content-Disposition attachment; filename="Employee List.xls"
Vary Accept-Encoding
Content-Encoding gzip
Content-Type application/excel
没有放气(Firebug 输出):
200 OK xxxxxxxx.co.za 100 KB
3.46s
ParamsHeadersPostPutResponseCacheHTML
Response Headers
Date Tue, 03 Nov 2009 13:06:00 GMT
Server Apache/2.2.4 (Ubuntu) mod_jk/1.2.23 PHP/5.2.3-1ubuntu6.4 mod_ssl/2.2.4 OpenSSL/0.9.8e
Content-Disposition attachment; filename="Employee List.xls"
Content-Length 102912
Content-Type application/excel
最佳答案
尝试强制使用最高压缩级别并确保影响压缩率的其他指令具有合理的值(有关更多信息,请参阅 mod_deflate reference):
DeflateCompressionLevel 9
DeflateBufferSize 8096
DeflateMemLevel 9
DeflateWindowSize 15
同样根据IANA ,MS Excel 内容类型应该是 application/vnd.ms-excel
,这也是我的安装 Apache/2.2.8 (Ubuntu) 在询问 xls 文件时返回的内容。所以你的 Apache 的行为不相似有点奇怪。任何 xls 文件都会发生同样的事情吗?如果不是,则特定文件可能有问题。
这有点远,但是如果将 application/vnd.ms-excel
添加到 AddOutputFilterByType
列表中会发生什么?
关于compression - 使用 apache deflate 模块压缩 xls 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1667133/