简体   繁体   English

关于gzip的困惑,是否已压缩?

[英]Confusion about gzip, is it compressed or not?

Sorry to bother you with a question that seems very well documented, but none of the things I tried was completely satisfying. 很抱歉打扰您一个似乎证据充分的问题,但是我尝试过的所有事情都没有完全令人满意。

My Company switched from a hosting package to a manages Server just last week and I'm still in the process of optimising it. 上周,我的公司从托管程序包切换到管理服务器,但我仍在对其进行优化。

Now, Googles PageSpeed Insights tell me, it is not compressed , as does GTMetrix . 现在,Google的PageSpeed Insights告诉我, 它没有GTMetrix一样被压缩 GidNetwork tells me compression works fine. GidNetwork告诉我压缩工作正常。

I have already added 我已经加了

<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

to my .htaccess, (as recommended here ) which works correctly, other settings I've changed are fine, as well as 到我的.htaccess(按此处的建议)正常运行,我更改的其他设置也可以,

zlib.output_compression = On

to my php.ini. 到我的php.ini。 The entire .htaccess and php.ini can be seen at jsFiddle . 整个.htaccess和php.ini可以在jsFiddle上看到。

Headers sent and received in both Firefox and Chrome claim that compression is happening. 在Firefox和Chrome中发送和接收的标头声称正在压缩。

I also created a httpd.conf in my home directory, because none existed on my server yet. 我还在我的主目录中创建了一个httpd.conf ,因为服务器上还不存在该httpd.conf Should I move the file somewhere else? 我应该将文件移到其他地方吗?

What I really want to know: 我真正想知道的是:

Soo... what am I doing wrong? 太...我在做什么错? Is it compressed? 压缩了吗? Is it not? 不是吗 How can I make google 'see' the compression? 我怎样才能使谷歌“看到”压缩?

Thank you very much for your help. 非常感谢您的帮助。

This should be the function you need, it should automatically generates the headers you need: 这应该是您需要的功能,它应该自动生成您需要的标头:

http://www.php.net/manual/en/function.gzdecode.php http://www.php.net/manual/en/function.gzdecode.php

anyway check your php version because it works only with php 5.4.0 or later ones. 无论如何,请检查您的php版本,因为它仅适用于php 5.4.0或更高版本。

Although my browser accepts deflate/gzip encoding ( Accept-Encoding: gzip, deflate ), your server does not answer using compressed data: 尽管我的浏览器接受deflate / gzip编码( Accept-Encoding: gzip, deflate ),但是您的服务器无法使用压缩数据进行应答:

HTTP/1.1 200 OK
Date: Tue, 11 Mar 2014 09:41:45 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=2, max=200
Etag: "96-100e9-4f4517d791912"
Expires: Fri, 11 Apr 2014 13:28:25 GMT
Cache-Control: max-age=2692000, public
Vary: User-Agent

If it was compressed, the server would send also 如果被压缩,服务器还将发送

Content-Encoding:   deflate

Use FireBug or the dev console to see the headers. 使用FireBug或开发控制台查看标头。 It must be your httpd.conf. 它必须是您的httpd.conf。 You cannot simply create this file in your home directory and Apache will load it. 您不能简单地在主目录中创建此文件,Apache会加载它。

Have a look in /etc/apache* and /etc/httpd/* for config files. /etc/apache*/etc/httpd/*查看配置文件。

You have already enabled gzip compression but you haven't set it to compress some file types such as javascript and css. 您已经启用了gzip压缩功能,但尚未将其设置为压缩某些文件类型,例如javascript和css。 That is why Googles PageSpeed was tried to suggest to enable compression. 这就是为什么Google的PageSpeed试图建议启用压缩的原因。 To enble compression for those two types, use 要使这两种类型的压缩有效,请使用

AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript

What worked for me in the end to compress the js/css files that were left uncompressed for reasons I don't quite get yet is described here . 到底是什么工作对我来说来压缩留给未压缩的原因,我不完全得到尚未被描述的JS / CSS文件在这里

In this method, javascript and css-files are forcibly gzipped by a php-script. 在这种方法中,javascript和css文件被php脚本强制压缩。 It also sets new "Expire"-Headers, so if you want caching for more than 5 Minutes, change the number. 它还设置了新的“ Expire”标题,因此,如果要缓存5分钟以上,请更改数字。 Adding different files is trickier, but possible, I think. 添加不同的文件比较麻烦,但我认为可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM