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

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

问题描述

我有一个单页面应用程序(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 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屋!

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