2

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

结果:

在此处输入图像描述

编辑:我正在使用“调试=假”;所有其他资源均为 200(来自缓存)

4

1 回答 1

6

我相信您走在正确的轨道上,但您需要更进一步,并在您的 clientCache 设置中添加一个选项(cacheControlCustom="must-revalidate"):

    <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 中解释更多。

于 2012-05-29T20:06:11.353 回答