【发布时间】:2011-03-23 15:11:51
【问题描述】:
如果我使用 Google Chrome 对我的网站进行审核,我会在利用浏览器缓存部分收到此消息:
以下资源缺少 缓存过期。做的资源 未指定到期可能不是 被浏览器缓存:
所有图片的列表如下。我在利用代理缓存中收到了类似的通知:
考虑添加一个“Cache-Control: 公共”标题到以下 资源:
除了图片,我还收到了关于 HTML、CSS 和 JavaScript 文件的通知:
以下资源是明确的 不可缓存。考虑制作它们 如果可能,可缓存:
这很有趣,因为我一直在努力缓存所有静态内容(图片除外,我刚刚离开了 Apache 的默认设置)。 Firefox 确实将所有这些项目都存储在缓存中。
我的 HTTP 标头有什么需要改进的地方吗?
这是删除浏览器缓存后加载的某些项目的完整标题集。图片使用我之前没有真正检查过的默认设置,其余的应该缓存三个小时。我可以使用.htaccess 和PHP 设置标题。
PNG
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2010 12:46:14 GMT
Server: Apache
Last-Modified: Thu, 18 Mar 2010 21:40:54 GMT
Etag: "c48024-230-4821a15d6c580"
Accept-Ranges: bytes
Content-Length: 560
Keep-Alive: timeout=4
Connection: Keep-Alive
Content-Type: image/png
HTML
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2010 12:46:13 GMT
Server: Apache
X-Powered-By: PHP/5.2.11
Expires: Sat, 31 Jul 2010 15:46:13 GMT
Cache-Control: max-age=10800, s-maxage=10800, must-revalidate, proxy-revalidate
Content-Encoding: gzip
Vary: Accept-Encoding
Last-Modified: Wed, 24 Mar 2010 20:30:36 GMT
Keep-Alive: timeout=4
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-15
CSS
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2010 12:48:21 GMT
Server: Apache
X-Powered-By: PHP/5.2.11
Expires: Sat, 31 Jul 2010 15:48:21 GMT
Cache-Control: max-age=10800, s-maxage=10800, must-revalidate, proxy-revalidate
Content-Encoding: gzip
Vary: Accept-Encoding
Last-Modified: Thu, 18 Mar 2010 21:40:12 GMT
Keep-Alive: timeout=4
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/css
JavaScript
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2010 12:48:21 GMT
Server: Apache
X-Powered-By: PHP/5.2.11
Expires: Sat, 31 Jul 2010 15:48:21 GMT
Cache-Control: max-age=10800, s-maxage=10800, must-revalidate, proxy-revalidate
Content-Encoding: gzip
Vary: Accept-Encoding
Last-Modified: Thu, 18 Mar 2010 21:40:12 GMT
Keep-Alive: timeout=4
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/x-javascript
更新
我已经测试了 Jumby 的建议并将我的 CSS 的有效期设置为 1 年:
Cache-Control:max-age=31536000, s-maxage=31536000, must-revalidate, proxy-revalidate
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:4198
Content-Type:text/css
Date:Mon, 02 Aug 2010 20:48:56 GMT
Expires:Tue, 02 Aug 2011 20:48:56 GMT
Keep-Alive:timeout=5, max=99
Last-Modified:Thu, 18 Mar 2010 20:40:12 GMT
Server:Apache/2.2.14 (Win32) PHP/5.3.1
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.1
但是,Chrome 仍然声称“明确不可缓存”。
【问题讨论】:
-
刚遇到类似的问题,不管我做什么,chrome 审计总是在窃听。