我在Apache 2.2上使用mod_deflate,压缩级别设置为9.我根据YSlow(v2)的建议调整了网站的每个可能方面,并设法获得整体A级(总分: 91)以及所有类别除外:
YSlow仍然用F报告,并告诉我在我的CSS和JS文件上使用gzip.以下是YSlow报告的截图(该域名因隐私而模糊不清):YSlow报告的屏幕截图:http: //img29.imageshack.us/img29/9160/yslowreportdomainblurre.jpg
但是,像GIDNetwork GZIP Test这样的网站报告完美的压缩!
# Below uses mod_deflate to compress text files. Never compress binary files.
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# compress content with type html, text, js, and css
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/xml image/svg+xml application/javascript application/x-javascript application/atom_xml application/rss+xml application/xml application/xhtml+xml application/x-httpd-php application/x-httpd-fastphp
# Properly handle old browsers that do not …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用'mod_deflate'(以及其他需要扩展)将GZIP压缩应用到我的本地托管站点(Apache,2.4.4.0).
这是我正在使用的代码(.htaccess):
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary
Run Code Online (Sandbox Code Playgroud)
我试图通过添加以下内容来修复它:
AddType text/css .css
AddType text/javascript .js
Run Code Online (Sandbox Code Playgroud)
因为我认为它不会识别类型但它也不起作用.JS和CSS文件都位于rootfolder/js和rootfolder/css中,可能是程序吗?
编辑:我正在使用YSlow @ Chrome查看它是否正常工作.
我启用gzip压缩以提高Google PageSpeed Insights的速度:
如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.svg,将节省144.1 KB(减少65%).如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.ttf,将节省62.6 KB(减少49%).如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.woff,将节省2.6 KB(减少5%).
我使用Apache服务器,我将此代码添加到.htacess:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle …Run Code Online (Sandbox Code Playgroud) 我负责用PHP编写的API的后端部分,主要由Flash客户端使用.现在发生的事情是:Flash客户端进行调用,后端加载必要的数据,执行任何必要的处理和后期处理,记录和缓存,然后将结果返回给客户端.
我希望发生的是尽快将数据返回给客户端,关闭连接,然后完成客户端不必关心的所有事情.这可能会使API看起来更具响应性.遵循这里的建议:
http://php.net/manual/en/features.connection-handling.php
实际上是有效的,除了我必须关闭gzip编码以使其工作,这是不太实际的.我们在apache中使用mod_deflate,因此使用它的解决方案将是理想的,但如果有必要,我还会考虑使用不同的方法来gzip我们的内容.
它看起来像应该有办法让阿帕奇知道"我送你所有我要发送的数据,"但我似乎无法找到这样的事情.
对于那些想知道的人,是的,我可以尽早清除结果,但Flash客户端将不会处理它们,直到连接关闭.
我正在尝试在我们的网站上使用大管道概念。这意味着尝试以块的形式发送响应,而不是整体发送响应,以便用户感觉该页面很快。我通过在 java 中的响应对象上使用flushBuffer方法成功地做到了这一点。但是现在,当我尝试使用 apache mod_deflate 模块压缩内容时,分块丢失了。
这是 apache 用于压缩内容的配置
**
DeflateBufferSize 100
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate
Run Code Online (Sandbox Code Playgroud)
这是apache中打开deflate时的响应头
连接:保持活动
内容编码:gzip
内容长度:7916
内容类型:text/html;字符集 = UTF-8
日期:2012 年 1 月 27 日星期五 20:11:11 GMT
保持活动:超时 = 300,最大值 = 3997
服务器:Apache
Vary:Accept-Encoding
apache 中关闭 deflate 时的响应头
连接:保持活动
内容类型:text/html;字符集 = …
我有以下(简化的)文件夹/文件结构:
/.htaccess
/test.php
/api/web/index.php
Run Code Online (Sandbox Code Playgroud)
以及 apache 配置中的以下指令:
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
SetInputFilter DEFLATE
</IfModule>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我正在发送一个带有 gzipped 正文的 POST 请求,其中包含适当的标头:
POST /test.php HTTP/1.1
Host: 192.168.1.248
Authorization: Bearer ed717c077e4bf81201196011adb457731b24e19d
Content-Type: application/json
Content-Encoding: gzip
Run Code Online (Sandbox Code Playgroud)
我有.htaccess文件的以下配置:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/(.*) api/web/index.php/$1 [NC,L]
Run Code Online (Sandbox Code Playgroud)
问题是,如果我张贴到/test.php,一切都按预期工作,正文放气,我可以恰到好处地访问解压缩的内容。
但是,如果我发布到重定向(/api/或/api/v1/project)的内容,则index.php脚本不会解压缩正文。
我认为它必须与RewriteRule忽略SetInputFilter指令的指令有关,但是,我该如何避免这种情况?
我试图SetInputFilter直接在 .htaccess 中添加指令而没有解决问题(可能是它不在正确的地方?)。
你知道我该如何解决这个问题吗?
我正在使用apache基准测试进行简单的负载测试:
ab -n 1 http://localhost/mysite/index/index/
Run Code Online (Sandbox Code Playgroud)
我希望看到有/没有mod_deflate的性能
在我的httpd.conf中:
#mod_deflate enabled
LoadModule deflate_module modules/mod_deflate.so
#mod_deflate disabled
#LoadModule deflate_module modules/mod_deflate.so
Run Code Online (Sandbox Code Playgroud)

看起来没有mod_deflate的服务器的性能比启用mod_deflate要好(参见"测试时间","每秒请求数"和"每个请求的时间").
另外,我不明白为什么在启用deflate的情况下总转移量会更大
请解释一下
谢谢
卢卡
我有一个带有 centos 6 的 linode 服务器,因为它不支持 mod_gzip,我正在使用 mod_deflate。
这是我在 .htacess 中的代码
<IfModule mod_deflate.c>
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
当我使用http://www.whatsmyip.org/http-compression-test/进行测试时,它说“我的网站是 gzipped”,但是当我在 chrome 中使用 pagespeed 时,它仍然建议“启用压缩”
怎么了?我的 .htaccess 代码有问题吗?
我想保持我的web服务器的所有静态文件在本地压缩,并根据请求压缩或不压缩它们.
在这些问题的答案我怎么能预先压缩与Apache 2.X的mod_deflate模块文件吗?,接近,因为实际上通过启用MultiViews并使用正确的AddEncoding,我可以让Apache foo.tar.gz在我请求时从我的web服务器返回压缩文件foo.tar,并且它带有正确的Content-Encoding:标头.
但这仅在客户端包含Accept-Encoding: gzip在发送到服务器的标头中时才有效.OTOH如果客户端不支持gzip编码,我的服务器告诉我,foo.tar对我来说没有"可接受" .
如果我使用它,我可以让Apache在发送之前解压缩该tarball AddOutputFilter INFLATE tar.但是,如果我这样做,那么服务器也会在我请求时foo.tar.gz(或者当我指定我接受gzip编码时)解压缩内容,这显然是我不想要的.
那么当客户端不支持gzip内容编码时如何让Apache解压缩文件,而在其他情况下如何提供预压缩文件呢?
编辑:根据@ covener的建议,我尝试了以下方法:
AddEncoding x-gzip .gz .tgz
RemoveType application/x-gzip .gz .tgz
AddType application/x-tar .tgz
<Location /packages>
FilterDeclare smgunzip CONTENT_SET
FilterProvider smgunzip INFLATE req=Accept-Encoding !$gzip
FilterChain smgunzip
</Location>
Run Code Online (Sandbox Code Playgroud)
[在这里使用Apache-2.2.22.]但结果实际上比前三行更糟糕:当我请求.tar.gz文件时,它现在返回而没有"Content-Encoding:",当我请求.tar文件时,我收到了tar.gz的内容(即仍然是压缩的),无论"Accept-Encoding:"标题如何,仍然没有"Content-Encoding:".
我有一个Liquid Web VPS帐户,我已确保mod_deflate已安装且正在运行/活动.
我曾经通过PHP gzip我的css和js文件,以及我的PHP文件本身...但是,我现在尝试通过mod_deflate这样做,它似乎适用于除PHP文件之外的所有文件.(Txt文件工作正常,css,js,静态HTML文件,只是通过PHP文件生成的任何内容.)我该如何解决这个问题?
(我使用了cPanel中"优化网站"下的"压缩所有内容"选项,它在主目录中创建了一个.htaccess文件(不是public_html,高出一个级别),文本与"压缩除图像之外的所有内容"完全相同" http://httpd.apache.org/docs/2.0/mod/mod_deflate.html上的示例)
.htaccess文件:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] …Run Code Online (Sandbox Code Playgroud) mod-deflate ×10
apache ×7
.htaccess ×4
gzip ×4
php ×3
compression ×2
pagespeed ×2
benchmarking ×1
chunked ×1
flash ×1
httpd.conf ×1
mod-rewrite ×1
yslow ×1