预期压缩内容

发布于 2024-07-29 19:34:10 字数 602 浏览 4 评论 0原文

我在我的网站上启用了 gzip 压缩,并使用以下工具进行了测试:

不过,Firefox 及其所有产品扩展程序(Firebug、Yslow 和 Google Page Speed)表示它们接收非压缩内容。

text/html 由 php 的 ob_gzhandler 压缩,它也关心 headers。

我不使用代理。

我究竟做错了什么?

I enabled gzip compression on my website, and tested with the following tools:

Though, Firefox and all its extensions (Firebug, Yslow and Google Page Speed) say they receive noncompressed content.

text/html is compressed by php's ob_gzhandler, which cares about headers as well.

I don't use proxy.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花开浅夏 2024-08-05 19:34:10

这并不是您所期望的答案,但是您是否尝试过不使用 PHP 而是使用 Apache 来压缩数据?

这可以使用 mod_deflate 来完成。

有几件事:

  • 这意味着 PHP 的计算量会减少,
  • 这也意味着您的 CSS/JS 文件可以压缩为(这是最好的部分;-) 考虑到它们的大小,现在压缩它们可能不是一件坏事......

作为旁注:为了帮助我们找出 PHP 压缩出现的问题,您能否提供更多信息? 比如您网站的 URL(如果是公开的),以及一些代码?


编辑现在我们有了网址http://ego.pestaa.hu/

当我转到该页面时,响应的标头如下:

HTTP/1.x 200 OK
Date: Sat, 01 Aug 2009 21:53:37 GMT
Server: Apache
X-Powered-By: PHP/5.2.6
**Content-Encoding: gzip**
Vary: Accept-Encoding
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

(使用带 LiveHTTPHeaders 扩展的 firefox 3.5)

您指定的三个测试站点也表示您的页面已被 gzip 压缩。

你找到问题所在了吗?

您确定这不是来自您的浏览器的内容,它不会在请求中发送以下标头:

Accept-Encoding: gzip,deflate

在其他答案后编辑

引用评论:

问题的根源可能不是
我的网站,但我的 isp/浏览器/路由器。
其中一个可以解压每一个
组件在到达内部之前
流程。

哦,如果问题不是你的网站,我想我完全误解了这个问题 - 对此感到抱歉:-( 我以为你不知道如何从你的网站服务器 gzip 压缩内容。

而且我想我不是唯一的一个,顺便说一句

如果问题与您网站的配置无关,那么,有两种可能性:

  • 也许是 firefox 配置错误? 如果您转到 about:confignetwork.http.accept-encoding 会说什么? 对我来说,如果问题来自于你的 ISP 或类似的东西,那就是 gzip,deflate
  • 任何人都无能为力......

That's not really the answer you might expect, but did you try not compressing out data with PHP, but with Apache ?

This can be done use mod_deflate.

Couple of things :

  • it would mean less calculations for PHP
  • it would also mean (and that's the nicest part ;-) ) that your CSS/JS files could be compresses to ; considering the size of those, nowadays, it might not be a bad thing to compress them...

As a sidenote : to help us figure out what's going wrong with the compression by PHP, could you give more informations ? Like the URL of your site (if it's public), and some code ?


EDIT now that we have the URL : http://ego.pestaa.hu/

When I go to that page, the response's headers are as follow :

HTTP/1.x 200 OK
Date: Sat, 01 Aug 2009 21:53:37 GMT
Server: Apache
X-Powered-By: PHP/5.2.6
**Content-Encoding: gzip**
Vary: Accept-Encoding
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

(using firefox 3.5 with LiveHTTPHeaders extension)

The three testing sites you indicated also say that your page is gzipped.

Did you find what the problem was ?

Are you sure this is not something coming from your browser, that would not send the following header in the request :

Accept-Encoding: gzip,deflate

EDIT after other answer

Quote from the comments :

the source of problem probably isn't
my website but my isp/browser/router.
One of them may decompress every
component before it reaches internal
processes.

Oh, if the problem is not your website, I think I totally mis-understood the question -- sorry about that :-( I thought you didn't know how to server gzipped content from your website.

And I think I'm not the only one, btw

If the problem has nothing to do with your website's configuration, then, two possibilities :

  • maybe a mis-configuration of firefox ? If you go to about:config, what does the network.http.accept-encoding say ? For me, it's gzip,deflate
  • if the problem is coming from your ISP or something like that, there's nothing anyone can do...
吹梦到西洲 2024-08-05 19:34:10

除了以下之外,还可以尝试 Live Http Headers firefox 插件其他。 它会打开一个窗口,显示来回时的确切请求/响应标头,因此您毫无疑问地知道接受编码和响应编码是什么。

Try the Live Http Headers firefox plugin in addition to the others. It opens a window showing the exact request/response headers as they go back and forward, so you know without doubt what the accept-encoding and response-encoding is.

诗酒趁年少 2024-08-05 19:34:10

您是否尝试过在 Apache/您的 Web 服务器中启用 gzip?

Have you tried just enabling gzip in Apache/your web server instead/as well?

水溶 2024-08-05 19:34:10
  • 您确定正在使用 Firefox 扩展测试相同的 URL 吗?
    • 在 PHP 中使用 ob_gzhandler 会压缩 PHP 页面的输出,但 YSlow 和其他人还会警告您有关未压缩的 css/javascript 文件的信息。
  • 检查浏览器是否发送正确的标头。 浏览器通常发送“Accept-encoding:gzip”标头来告诉脚本/网络服务器它接受压缩内容。 测试脚本肯定会发送该信息,但您的浏览器可能不会。
  • Are you sure you're testing the same URLs with the Firefox extensions?
    • Using the ob_gzhandler in PHP will compress the output of your php pages, but YSlow and others warn you also about uncompressed css/javascript files.
  • Check that the browser is sending the correct headers. A browser usually sends the "Accept-encoding: gzip" header to tell the script/webserver it accepts compressed content. The testing scripts will surely send that but your browser might not.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文