過期/緩存控制標頭的問題 (Problem with Expires/Cache-Control Headers)


問題描述

過期/緩存控制標頭的問題 (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?

(by A_Mfuttta)

參考文件

  1. Problem with Expires/Cache‑Control Headers (CC BY‑SA 3.0/4.0)

#caching #performance #apache






相關問題

Heroku 上的頁面緩存技巧? (Page caching trick on Heroku?)

Array of Structs selalu lebih cepat daripada Structs of arrays? (Array of Structs are always faster than Structs of arrays?)

使用 Varnish 更改標頭中的引用者 (Change Referrer in header using Varnish)

清理 ios 中的 uiwebview 緩存 (clean uiwebview cache in ios)

緩存整個表 (Caching the entire table)

過期/緩存控制標頭的問題 (Problem with Expires/Cache-Control Headers)

強制 L1 緩存上的一些數據 (force some data on L1 cache)

Facebook API - 在服務器上緩存響應 (Facebook API - cache response on server)

ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)

如果小於 X 天,如何從磁盤讀取文件,如果舊,則重新獲取 html 文件 (How to read a file from the disk if less than X days old, if older, refetch the html file)

當您的應用服務器託管在不同的雲服務上時,如何安全地從 Firebase 託管上的 CDN 緩存中受益 (How to safely benefit from CDN caching on Firebase Hosting when your app's server is hosted on a different Cloud service)

如何使用java處理緩存中的鎖定(ConcurrentHashMap) (How to handle lock in cache (ConcurrentHashMap) using java)







留言討論