我想为我网站的静态内容启用缓存。我发现这个方法使用IIS缓存控制选项,我猜它适用于服务器端:
<caching>
<profiles>
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
</profiles>
</caching>
此外,我发现此解决方案用于静态内容的客户端缓存:
<staticContent>
<clientCache cacheControlMaxAge="7.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
添加上述两个代码后,我已清除历史记录并使用了硬刷新。但是,当我在Chrome控制台中检查网络标签时,静态内容的加载时间仍然是以秒为单位(而不是来自用户缓存)。我不得不说在开发者控制台中也取消选中禁用缓存的复选框。
修改:将kernelCachePlicy
更新为CacheUntilChange
后,我使用netsh http show cachestate
检查缓存状态,这是一个示例输出,但浏览器仍然加载来自服务器的文件不是来自本地缓存。
URL: [PTAH TO A PNG FILE]
Status code: 200
HTTP verb: GET
Cache policy type: User invalidates
Creation time: 2017.11.1:20.41.18:0
Request queue name: MyPool
Content type: image/png
Content encoding: (null)
Headers length: 244
Content length: 1507
Hit count: 5
Force disconnect after serving: FALSE