apache 上的 mod_deflate 导致浏览器执行 200 而不是 304?

发布于 2024-07-22 14:12:06 字数 836 浏览 5 评论 0原文

我在 Ubuntu 计算机上的 Apache 2 上启用了 mod_deflate,并注意到我的浏览器在页面刷新时不会缓存压缩文件类型。 我使用firebug的网络设置来检查这一点并在另一台计算机上进行了验证。

在mod_deflate下,如果我压缩css和js文件,浏览器每次都会发出请求。

如果我关闭 mod_deflate,浏览器会收到 css 和 js 文件的 304 错误码。 最终效果是,如果我没有启用 mod_deflate,页面刷新时加载速度会更快。

我打开的其他模块之一是否会导致此问题? Apache 中是否存在某种我未正确设置的缓存设置?

我的启用 mods 的目录: 别名.conf
authz_default.load
autoindex.conf
deflate.load
mime.conf
php5.conf
setenvif.load
别名.load
authz_groupfile.load
自动索引.load
目录.conf
mime.load
php5.load
ssl.conf
auth_digest.load
authz_host.load
cgi.load
目录.加载
协商.conf
重写.load
ssl.load
authn_file.load
authz_user.load
deflate.conf
环境负载
协商.负载
设置环境配置文件

I enabled mod_deflate on Apache 2 on an Ubuntu machine and noticed that my browser doesn't cache the compressed file types on page refreshes. I used firebug's net settings to check this and verified on another computer.

Under mod_deflate if I compress css and js files, the browser makes a request each time.

If I turn off mod_deflate, the browser gets a 304 for the css and js files. The net effect is that the pages load faster on a refresh if I don't have mod_deflate enabled.

Could one of the other modules I have turned on be causing this? Is there some sort of cache setting in Apache that I'm not setting correctly?

My mods-enabled directory:
alias.conf
authz_default.load
autoindex.conf
deflate.load
mime.conf
php5.conf
setenvif.load
alias.load
authz_groupfile.load
autoindex.load
dir.conf
mime.load
php5.load
ssl.conf
auth_digest.load
authz_host.load
cgi.load
dir.load
negotiation.conf
rewrite.load
ssl.load
authn_file.load
authz_user.load
deflate.conf
env.load
negotiation.load
setenvif.conf

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

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

发布评论

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

评论(2

羁〃客ぐ 2024-07-29 14:12:07

这实际上是 Apache 关于 gzip 的 Etag 的一个错误:

https://issues.apache .org/bugzilla/show_bug.cgi?id=45023

关闭 ETag 可以工作,但有更好的解决方法:

<IfModule mod_headers.c>
    RequestHeader  edit "If-None-Match" "^(.*)-gzip$" "$1"
    Header  edit "ETag" "^(.*[^g][^z][^i][^p])$" "$1-gzip"
</IfModule>

It's actually a bug of Apache regarding Etags with gzip:

https://issues.apache.org/bugzilla/show_bug.cgi?id=45023

Turning ETags off works but there is better workaround:

<IfModule mod_headers.c>
    RequestHeader  edit "If-None-Match" "^(.*)-gzip
quot; "$1"
    Header  edit "ETag" "^(.*[^g][^z][^i][^p])
quot; "$1-gzip"
</IfModule>
暖风昔人 2024-07-29 14:12:06

我以为我之前回答过这个问题...但没有被发布。 抱歉,如果它最终成为双重帖子。

事实证明是 etags 导致了这个问题。 我不知道为什么,但是当我们关闭 etag 时,浏览器开始正确缓存内容。 在 Google 上搜索 FileETags。

现在,我不确定为什么关闭 etags 会这样做......如果有人知道,请发帖到这个帖子。 谢谢!

I thought I answered this before...didn't get posted though. Sorry if it ends up being a double post.

Turns out that it was etags that were causing the problem. I'm not sure why but when we turned off etags, the browser started caching things correctly. Search for FileETags on Google.

Now, I'm not sure why turning etags off would do this...if anyone knows, please do post to this thread. Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文