且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Web服务器上设置gzip压缩?

更新时间:2023-08-31 21:49:40

正如其他人提到的mod_deflate为你,但我想你需要手动进行,因为它是一个嵌入式环境。

As others have mentioned mod_deflate does that for you, but I guess you need to do it manually since it is an embedded environment.

首先你应该留下文件foo.js的名称, 。

First of all you should leave the name of the file foo.js after you gzip it.

您不应该更改HTML文件中的任何内容。因为文件仍然是foo.js

You should not change anything in your html files. Since the file is still foo.js

在(gzipped)foo.js的响应头中,您发送标题

In the response header of (the gzipped) foo.js you send the header

Content-Encoding: gzip

诀窍。客户端请求foo.js并接收Content-Encoding:gzip,然后是gzipped文件,它会在解析之前自动解压缩。

This should do the trick. The client asks for foo.js and receives Content-Encoding: gzip followed by the gzipped file, which it automatically ungzips before parsing.

当然这假设你确定客户端理解gzip编码,如果你不确定,你应该只发送gzipped数据,当请求头包含

Of course this assumes your are sure the client understands gzip encoding, if you are not sure, you should only send gzipped data when the request header contains

Accept-Encoding: gzip