我正在使用“squishit”组合我的.js和.css文件。 问题是,当所有其他资源为200(来自缓存)时,Squishit Bundle会导致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"))
.

结果:

编辑: 我使用“debug= false”; 所有其他资源为200(来自缓存)

有帮助吗?

解决方案

我相信你在正确的轨道上,但你需要更进一步,并将一个更多的选择添加到您的客户端库设置(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-Finified - 自特定静态文件。设置CacheControlMaxage只会到目前为止,尤其是当您在服务器上修改文件时,您的客户端可能不会自动重新拉动文件。您拥有的设置(500天)只会在客户机的计算机上拉动文件500天。如果这是你的意图,很棒。(此外,Squishit将屏蔽一些缓存行为,因为在包中更改JS / CSS文件,将生成不同的哈希名称。)

评论中的URL可以从MSDN解释一下。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top