2012-05-20 36 views
2

我正在使用「SquishIt」來合併我的.js和.css文件。 問題是當所有其他資源都是200(來自緩存)時,squishit包會導致304(未更改)。如果我以常規方式放置文件,我會得到想要的結果。 我的代碼的一個例子:squishit給出304(而不是修改)而不是200(來自緩存)

@MvcHtmlString.Create(@Bundle.JavaScript().Add("~/Scripts/Libs/jquery.cookie.js").Add("~/Scripts/Libs/jquery.dynatree.min.js").Add("~/Scripts/Libs/jquery.json-2.3.min.js").Add("~/Scripts/Libs/jsrender.js").Add("~/Scripts/Libs/jstorage.min.js").Add("~/Scripts/Common/utils.js").Add("~/Scripts/DataServices/AccountDataServices.js").Add("~/Scripts/AccountSelection.js").WithMinifier<SquishIt.Framework.Minifiers.JavaScript.MsMinifier>().Render("~/Scripts/AccSelectionscriptBandle_#.js")) 

其結果是:

enter image description here

EDIT: 我使用 「調試=假」; 所有其他資源是200(從緩存)

+1

你必須看看頭,但我懷疑它使用etag進行緩存控制。 「未修改」狀態表示瀏覽器實際上正在使用緩存,但它會檢查服務器以檢查當前的etag值,以便知道它可以使用緩存的版本。 – Pointy

+1

謝謝,我添加了 到web.config - 解決了問題 –

回答

5

我相信你是在正確的軌道上,但你需要更進一步,並添加一個選項到你的clientCache設置(cacheControlCustom =「必須重新驗證」):

<staticContent> 
     <!-- A clients cache will expire 90 days after it is loaded --> 
     <!-- each static item is revalidated against the server to see if the LastModifiedDate is different than the If-Modified-Since date--> 
     <!-- http://msdn.microsoft.com/en-us/library/ms689443.aspx --> 
     <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" cacheControlCustom="must-revalidate"/> 
    </staticContent> 

的cacheControlCustom部隊對服務器進行檢查的lastModifiedDate和比較了If-Modified-Since的特定靜態文件。設置cacheControlMaxAge只會讓你感到滿意,尤其是當你修改服務器上的文件時,客戶端可能不會自動重新提取文件。您擁有的設置(500天)只會在該文件在客戶機上運行500天后才能將其拖出。如果那是你的意圖,那很好。 (此外,SquishIt將掩蓋一些緩存行爲,因爲更改包內的js/css文件將生成不同的哈希名稱。)

評論中的Url可能會解釋來自MSDN的更多內容。

+0

因此,任何人否則可以很容易地找到它,元素''位於'web.confg'中的'configuration/system.webServer'中 – nicodemus13

相關問題