以下哪一项更适合为 asp.net mvc2 应用程序设置静态内容(即 js、css、图像)的缓存选项:
** - Web.config:**
<?xml version="1.0"?>
<configuration>
<system.webServer>
<!--Caching-->
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
</staticContent>
</system.webServer>
</configuration>
或者
<?xml version="1.0"?>
<configuration>
<system.webServer>
<!--Caching-->
<staticContent>
<clientCache cacheControlMode="UseExpires" httpExpires="Tue, 31 Dec 2030 12:00:00 GMT"/>
</staticContent>
</system.webServer>
</configuration>
简而言之,我想知道哪个选项更好: UseMaxAge 、 UseExpires 。如果我使用 HttpModule 删除请求和响应 header 中的 ETag,会对它产生什么影响。
谁能帮我了解有关上述问题的更多详细信息吗?
谢谢和问候, 桑托什·库马尔·帕特罗
最佳答案
没有更好,它们是不同的。
- UseExpires 用于指定内容过期的 future 绝对时间。
- UseMaxAge 用于指定滑动过期时间。
我相信浏览器不会将内容缓存超过一年,因此您会看到您提供的指定 365 天的示例。
鉴于您的示例,我怀疑您正在尝试让客户端无限期(或尽可能长地)缓存内容,因此您可能想要使用:
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
这样,客户端会将内容缓存一年,或者直到由于其他原因(例如用户清除缓存或缓存达到限制)将其从浏览器缓存中删除为止。
关于caching - : UseMaxAge , UseExpires 哪个选项作为缓存选项更好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20857174/