使用 apache deflate 模块压缩 xls 内容

发布于 2024-08-09 17:51:37 字数 1323 浏览 4 评论 0原文

我正在尝试使用 apache deflate 模块压缩从我的应用程序发送的 Excel 电子表格。我已将以下行添加到我的启用站点的文件中:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/excel

但这似乎使响应数据更大???

使用 firebug,在没有模块的情况下,我从应用程序下载了 xls 电子表格,它下载了 100Kb 的数据,文件系统上的文件大小也如预期的那样为 100Kb。一旦我如上所述启用 deflate 模块并重复该过程,下载的数据量为 295Kb?但文件保存到文件系统后仍然只有 100Kb。

作为实验,我手动对保存的 xls 文件进行 gzip 压缩,并将其压缩到 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

不使用 deflate(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

I am trying to compress an excel spreadsheet being sent from my application using apache deflate module. I have added the following line to the my sites-enabled file:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/excel

But is seems to make the response data bigger???

Using firebug, without the module I downloaded the xls spreadsheet from the application and it downloaded 100Kb of data, the file size once on the filesystem was also 100Kb as expected. Once I enabled the deflate module as described above and repeated the process, the amount of data downloaded was 295Kb?? but the file was still only 100Kb once save on the filesystem.

As an experiment I manually gzipped the saved xls file and it compressed to 20Kb.

What am I doing wrong here?

Using deflate (Firebug output):

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

Without deflate (Firebug output):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2024-08-16 17:51:37

尝试强制使用最高压缩级别,并确保影响压缩比的其他指令具有合理的值(请参阅 mod_deflate 参考 了解更多信息):

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 列表中会发生什么?

Try forcing the highest compression level and ensure that other directives affecting compression ratios have sensible values (see mod_deflate reference for more info):

DeflateCompressionLevel 9
DeflateBufferSize 8096
DeflateMemLevel 9
DeflateWindowSize 15

Also according to IANA, the MS Excel content type should be application/vnd.ms-excel, and this is also what my installation Apache/2.2.8 (Ubuntu) returns when asked for an xls file. So it's a bit weird that your Apache doesn't behave similarly. Does the same thing happen for any xls file? If not, there could be something wrong with the particular file.

This is a bit long shot, but what happens if you add application/vnd.ms-excel to the AddOutputFilterByType list?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文