如何轻松、透明地将 gzip 压缩的 html 文件提供给用户的浏览器?
用户单击链接时,需要获取我的压缩 html 文件,他的浏览器将自动解压缩该文件,无需任何麻烦。我必须在服务器端做什么才能完成此任务?
谢谢!
——本
The user, when he clicks a link, needs to get my compressed html file that his browser will uncompress automatically, without any fuss. What must I do on the server side to accomplish this?
Thanks!
-- ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在从您的评论中看到,您实际上是在尝试让压缩文件在浏览器中透明地打开,而不仅仅是压缩整个 HTTP 响应。
这绝对是 ServerFault 的一个问题。它依赖于两件事:
(原始答案如下)
我几乎说这属于服务器故障,但我认为 SO 需要答案,因为它并不明显属于 SF,除非您了解工作机制,所以:
在大多数情况下,压缩 HTTP 响应是一种Web 服务器的功能,并且您或您的系统管理员需要配置 Web 服务器(例如带有 mod_deflate 的 Apache)才能使用该功能。
如果您的应用程序是自己的 Web 服务器,则需要查看 RFC 2616(HTTP/1.1 规范)和/或您正在使用的任何框架的文档。
如果您将网络服务器用作反向代理,我不确定什么是正确的事情......如果可能的话,可能仍然需要在网络服务器中。
I see now from your comment that you're literally trying to get compressed file to open transparently in a browser, not just compress the whole HTTP response.
That is definitely an issue for ServerFault. It relies on two things:
(Original answer below)
I almost said this belongs on Server Fault, but I think the answer is needed on SO because it's not obvious it belongs on SF unless you understand the mechanisms at work, so:
In most cases, compressing HTTP responses is a capability of web servers, and you or your sysadmin will need to configure the web server (e.g. Apache with mod_deflate) to use that capability.
In the event that your application is its own web server, you need to review RFC 2616 (the HTTP/1.1 spec) and/or the documentation for any framework you're using.
I'm not exactly sure what the right thing is if you're using the webserver like as a reverse proxy... Probably still needs to be in the webserver, if it's possible at all.
你运行什么服务器?
如果您有 Apache,则可以设置 mod_deflate
What server are you running?
If you have Apache, you can set up mod_deflate