如何禁用通过IIS提供的单页面应用程序HTML文件的缓存? [英] How to disable caching of single page application HTML file served through IIS?
问题描述
我有一个单页面应用程序(angular-js),它通过IIS提供。如何防止缓存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/caching
- web.config客户端缓存 - http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
- 元标记 - 使用< meta>用于关闭所有浏览器缓存的标签?
- web.config caching profiles - http://www.iis.net/configreference/system.webserver/caching
- web.config client cache - http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
- meta tags - Using <meta> tags to turn off caching in all browsers?
IIS是带有.NET Framework 4的7.5版本
IIS is version 7.5 with .NET framework 4
推荐答案
将以下内容添加到适用于Chrome,IE,Firefox和Safari的web.config解决方案中:
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>
这将确保 Cache-Control
index.html 时,> header设置为 no-cache
。
This will ensure that the that Cache-Control
header is set to no-cache
when requesting index.html
.
这篇关于如何禁用通过IIS提供的单页面应用程序HTML文件的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!