【发布时间】:2010-11-29 10:59:16
【问题描述】:
我使用的是 Apache 2.2.16。
我的 htdocs 文件夹中有以下 HTML 文件:
<html>
<link media="screen" type="text/css" href="/css/test.css" rel="stylesheet" />
<body>XXXX</body>
</html>
我正在尝试在我的浏览器中缓存 CSS 文件,这样它就不会再次请求它,除了在第一次加载页面时。
但是,每次我按刷新时,我都可以看到 CSS 文件再次从服务器加载。我在服务器日志中看到该文件的 200 个响应代码。
我的 httpd.conf 文件中有以下内容:
<LocationMatch "\.(css)$">
Header set Cache-Control "max-age=2592000"
Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT"
Header unset Last-Modified
Header set Content-Type text/css
Header unset ETag
</LocationMatch>
这是我的响应标头,由 Firebug 报告:
Date Mon, 29 Nov 2010 10:48:49 GMT
Server Apache/2.2.16 (Win32)
Accept-Ranges bytes
Content-Length 18107
Cache-Control max-age=2592000
Expires Thu, 15 Apr 2020 20:00:00 GMT
Content-Type text/css
Keep-Alive timeout=5, max=97
Connection Keep-Alive
我已经阅读了一些关于设置缓存标头的文章,但我只是看不到它的工作原理。
非常感谢任何建议。
【问题讨论】:
标签: performance apache caching