如何在Web服务器上设置gzip压缩? [英] How do I set up gzip compression on a web server?

查看:1077
本文介绍了如何在Web服务器上设置gzip压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入式网络服务器,它上面总共有2兆字节的空间。通常你的gzip文件为客户端受益,但这将节省我们在服务器上的空间。我读了,你可以只是gzip js文件,并将其保存在服务器上。我测试了在IIS上,我没有任何运气。

I have an embedded webserver that has a total of 2 Megs of space on it. Normally you gzip files for the clients benefit, but this would save us space on the server. I read that you can just gzip the js file and save it on the server. I tested that on IIS and I didn't have any luck at all. What exactly do I need to do on every step of the process to make this work?

这是我想象的会是这样:

This is what I imagine it will be like:


  1. gzip foo.js

  2. 在HTML中更改链接以指向foo.js.gz,而不是.js

  3. 在响应中添加一些标题?

感谢您的帮助。

-fREW

EDIT :我的网络服务器无法进行任何操作。它不是Apache或IIS;它是ZiLog处理器上的二进制文件。我知道你可以压缩流;我刚刚听说你也可以压缩文件一次,让它们压缩。

EDIT: My webserver can't do anything on the fly. It's not Apache or IIS; it's a binary on a ZiLog processor. I know that you can compress streams; I just heard that you can also compress the files once and leave them compressed.

推荐答案

正如其他人提到的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

这篇关于如何在Web服务器上设置gzip压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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