如何启用gzip? [英] How to enable gzip?

查看:28
本文介绍了如何启用gzip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些关于如何启用 gzip 的教程,但似乎对我没有任何作用,所以我的问题是如何启用 gzip.我在一个共享的 Dreamhost 托管服务器上,它运行 PHP 5.2 版和 Apache,从我发现这一行的 php 信息中,这可能有帮助吗?

I have found a couple of tutorials on how to enable gzip, but nothing seems to be working for me, so my question is how do i enable gzip. I am on a shared Dreamhost hosting server, It is running PHP version 5.2, and Apache, from the php info i have found this line, maybe this could help?

zlib

ZLib Support    enabled
Stream Wrapper support  compress.zlib://
Stream Filter support   zlib.inflate, zlib.deflate
Compiled Version    1.2.3.3
Linked Version  1.2.3.3

Directive   Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level   -1  -1
zlib.output_handler no value    no value

我也找到了这条线

_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate

不知道有没有关系.但这是我的第一个问题,其次,我有 Dropbox,托管一个 javscript 文件,我想知道是否可以将该文件压缩,它没有被压缩,所以有什么办法可以这样做吗?

I don't know if that has anything to do with it. But that is my first question, secondly, i have dropbox, hosting a javscript file, and I am wondering is it possible to have that file gzipped, It is not being transfered compressed, so is ther any way to do so?

推荐答案

您是否尝试过 ob_gzhandler?

<?php ob_start("ob_gzhandler"); ?>
<html>
  <body>
    <p>This should be a compressed page.</p>
  </html>
<body>

作为替代,使用 Apache Web 服务器,您可以添加 一个 DEFLATE 输出过滤器到你的顶级服务器配置,或者一个 .htaccess 文件:

As an alternative, with the Apache web server, you can add a DEFLATE output filter to your top-level server configuration, or to a .htaccess file:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml \
        text/css application/x-javascript application/javascript
</IfModule>

提示:有时检测网络服务器是否正在发送压缩内容非常棘手.这个在线工具可以帮助解决这个问题.

Tip: Sometimes it is pretty tricky to detect if the web server is sending compressed content or not. This online tool can help with that.

在我的 Web 浏览器中使用开发人员工具,我测试了一个 PHP 文件,以比较压缩和不压缩的大小.就我而言,差异是 1 MB(未压缩)和 56 KB 压缩.

Using the developer tools in my web browser, I tested a PHP file with and without compression to compare the size. In my case, the difference was 1 MB (non-compressed) and 56 KB compressed.

这篇关于如何启用gzip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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