LiveHttpHeaders:哪个缓存控制信息是正确的

发布于 2024-12-05 05:43:34 字数 1012 浏览 6 评论 0原文

在 Firefox 6 中使用 LiveHttpHeaders 我试图查看我的 css、JS 文件是否使用 htaccess 使用 Apache 的标头模块进行缓存。但我很困惑,“Cache-Control”数据中有 2 个值:

GET /proz/css/global.css HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost/proz/
Cookie: PHPSESSID=el34de37pe3bnp4rdtbst1kd43
If-Modified-Since: Fri, 16 Sep 2011 21:15:32 GMT
If-None-Match: "400000000b06a-2999-4ad157e5b4583"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Sat, 17 Sep 2011 03:04:50 GMT
Server: Apache/2.2.17 (Win32) PHP/5.2.8
Connection: Keep-Alive
Keep-Alive: timeout=5, max=99
Etag: "400000000b06a-2999-4ad157e5b4583"
Cache-Control: max-age=604800, public
Vary: Accept-Encoding

哪个是真实数据,第一个 Cache-Control 数据(max-age=0)还是后一个。

我还想知道在 htaccess 中使用 deflate 模块后如何确保我的 JS、CSS、HTML 文件被压缩。是的,标头和放气模块都已打开。

Using LiveHttpHeaders for Firefox 6 I was trying to see if my css, JS files being cached using Headers Module from Apache using htaccess. But I confuse, there are 2 values from the 'Cache-Control' data:

GET /proz/css/global.css HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost/proz/
Cookie: PHPSESSID=el34de37pe3bnp4rdtbst1kd43
If-Modified-Since: Fri, 16 Sep 2011 21:15:32 GMT
If-None-Match: "400000000b06a-2999-4ad157e5b4583"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Sat, 17 Sep 2011 03:04:50 GMT
Server: Apache/2.2.17 (Win32) PHP/5.2.8
Connection: Keep-Alive
Keep-Alive: timeout=5, max=99
Etag: "400000000b06a-2999-4ad157e5b4583"
Cache-Control: max-age=604800, public
Vary: Accept-Encoding

Which one is the true data, the first Cache-Control data (max-age=0) or the latter one.

I also would like to know how do I make sure that my JS, CSS, HTML files being compress after I use deflate module in htaccess. And yes, both headers and deflate modules are turn on.

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

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

发布评论

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

评论(1

策马西风 2024-12-12 05:43:34

此清单中有两部分:

  • 空行之前的部分是请求,由浏览器发送
  • 空行之后的部分是服务器发送的响应

Cache-Control: max-age=0<客户端(您的浏览器)发送的 /code> 告诉服务器(或中间的任何代理)发送文件的最新版本。当您点击刷新按钮时,浏览器通常会发送此消息。

服务器发送的 Cache-Control: max-age=604800, public 告诉客户端(您的浏览器或代理)该文件的有效期为 604800 秒,并且可以在这段时间内进行缓存。 (浏览器甚至不会尝试询问服务器是否存在更新的版本,除非您按刷新,就像在本例中所做的那样。)

服务器回复 304 Not Modified,这意味着您的浏览器已经有最新版本,不需要再次下载(它没有再次下载)。

Vary: Accept-Encoding 标头表明服务器根据客户端的 Accent-Encoding 标头做出了一些决定。这可能表明,如果服务器没有回复 304 Not Modified,它就会压缩该文件。

要验证最后一点,请清除缓存,再次请求文件,然后查看 Content-Encoding 标头的内容(如果数据被压缩,则必须是 gzip 或 deflate)。

There are two parts in this listing:

  • The part before the blank line is the request, sent by your browser
  • The part after the blank line is the response, sent by the server

The Cache-Control: max-age=0 sent by the client (your browser) tells the server (or any proxy in the middle) to send the most fresh version of the file. The browser usually sends this when you hit the refresh button.

The Cache-Control: max-age=604800, public sent by the server tells the client (your browser or a proxy) that the file is valid for 604800 seconds and can be cached for that time. (The browser won't even attemps to ask the server if a newer version exists, unless you hit refresh, as you did in this case.)

The server replied 304 Not Modified, this means that your browser already has the most recent version and it doesn't need to download it again (it did not downloaded it again).

The Vary: Accept-Encoding header indicate that the server taken some decisions based on the client's Accent-Encoding header. This may indicate that, if the server didn't replied 304 Not Modified, it would have compressed the file.

To verify this last point, clear your cache, and request the file again, and look at the content of the Content-Encoding header (must be gzip or deflate if the data is compressed).

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