2012-09-29 55 views
5

在IIS 7.5,我設置了cacheControlMaxAge爲一個像今年這樣IIS7 cacheControlMaxAge屬性不工作

<location path="Content/Images"> 
    <system.webServer> 
     <staticContent> 
     <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" /> 
     </staticContent> 
    </system.webServer> 
    </location> 

按照本指南:Setting Expires and Cache-Control: max-age headers for static resources in ASP.NET

然而,谷歌的PageSpeed工具仍然說,文件沒有被緩存:

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources: 
* https://local.example.com/Content/Images/image1.png (expiration not specified) 
(etc) 

爲什麼說「過期未指定」?

整個webapp通過https服務,這是一個因素嗎?

+2

你檢查過image1.png的http頭文件嗎?您可以在網絡選項卡下的瀏覽器開發工具(Chrome/FF/IE中的F12)中執行此操作。或者你可以使用提琴手。如果最大年齡已設置,所有現代瀏覽器都會通過https緩存項目。 –

+0

http頭文件說'Cache-Control:public',但沒有提到過期,將調用過期頭文件是什麼? –

+1

解決:將緩存屬性添加到'location path =「Content」'而不是'location path =「Content/Images」'解決了問題。 –

回答

3

我解決了這個改變從Content/Images指定的路徑,只是Content

<location path="Content"> 
    <system.webServer> 
     <staticContent> 
     <clientCache cacheControlCustom="public" 
        cacheControlMode="UseMaxAge" 
        cacheControlMaxAge="365.00:00:00" /> 
     </staticContent> 
    </system.webServer> 
    </location> 

所以它是固定的,但路徑的變化並沒有說清楚是什麼問題實際上是。

0

我發現在某些情況下,Google PageSpeed需要一點時間才能趕上最近做出的更改。確保您已完成整頁刷新並點擊PageSpeed本身的刷新按鈕。否則,在FireFox上使用Firebug似乎總能在net標籤中給出準確的結果。點擊該文件旁邊的加號圖標,然後檢查響應標題。

+1

我發現在頁面末尾添加不相關的查詢字符串會強制Google PageSpeed獲取最新版本。即http://www.example.com/testpage.htm?x=1 – EddieC