it-swarm.cn

如何确保我的内容通过Apache中的gzip发送?

我可以在Apache配置中搜索一些设置,以确保通过gzip发送所有页面,CSS和JavaScript吗?

它们是否位于不同操作系统的不同位置(如果是,我正在运行Debian)。

10
Mike

我把以下内容放在我的httpd.conf中,它似乎工作:

  # 20100709 added etag code
  FileETag MTime Size

  # 20100709 added compression START

  # Insert filter
  SetOutputFilter DEFLATE

  # 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] !no-gzip !gzip-only-text/html

  # Don't compress images
  SetEnvIfNoCase Request_URI \
  \.(?:gif|jpe?g|png)$ no-gzip dont-vary

  # Make sure proxies don't deliver the wrong content
  Header append Vary User-Agent env=!dont-vary

  # 20100709 added compression END

这个网站有一个很好的测试人员,可以看到你的网页是否是GZIP: http://www.whatsmyip.org/http_compression/

3
Darryl Hein

在Firefox中安装ySlow,它会告诉你哪些项目被gzip压缩。

2
corymathews

RedBot ,Cacheability Engine的继任者,以简单易读的网格格式测试多个性能和可​​缓存性指标的页面和内容。

示例: http://redbot.org/?descend=True&uri=http://www.Microsoft.com/en/us/default.aspx

0
JasonBirch