問題描述
過期/緩存控制標頭的問題 (Problem with Expires/Cache‑Control Headers)
我使用的是 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
我已經閱讀了一些關於設置緩存標頭的文章,但我只是看不到它的工作原理。
非常感謝任何建議。
參考解法
方法 1:
I've seen similar problems with configurations that manually set expires & cache‑control. Just letting mod_expires do that "heavy lifting" might already solve these issues?