如何禁用通过 IIS 提供的单页应用程序 HTML 文件的缓存? [英] How to disable caching of single page application HTML file served through IIS?
问题描述
我有一个通过 IIS 提供服务的单页应用程序 (angular-js).如何防止缓存 HTML 文件?该解决方案需要通过更改 index.html 或 web.config 中的内容来实现,因为无法通过管理控制台访问 IIS.
I have a single page application (angular-js) which is served through IIS. How do I prevent caching of HTML files? The solution needs to be achieved by changing content within either index.html or the web.config, as access to IIS through a management console is not possible.
我目前正在研究的一些选项是:
Some options I am currently investigating are:
- web.config 缓存配置文件 - http://www.iis.net/configreference/system.webserver/缓存
- web.config 客户端缓存 - http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
- 元标记 - 使用 <元>在所有浏览器中关闭缓存的标签?
IIS 是 7.5 版,带有 .NET 框架 4
IIS is version 7.5 with .NET framework 4
推荐答案
将以下内容添加到 web.config
解决方案中,适用于 Chrome、IE、Firefox 和 Safari:
Adding the following into web.config
solution worked across Chrome, IE, Firefox, and Safari:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="index.html">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
这将确保在请求 index.html
时将 Cache-Control
标头设置为 no-cache
.
This will ensure that the that Cache-Control
header is set to no-cache
when requesting index.html
.
这篇关于如何禁用通过 IIS 提供的单页应用程序 HTML 文件的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!