如何禁用通过 IIS 提供的单页应用程序 HTML 文件的缓存? [英] How to disable caching of single page application HTML file served through IIS?

查看:28
本文介绍了如何禁用通过 IIS 提供的单页应用程序 HTML 文件的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 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:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆