web-dev-qa-db-ja.com

IISを介して提供される単一ページアプリケーションHTMLファイルのキャッシュを無効にする方法

IISを介して提供される単一ページアプリケーション(angular-js)があります。 HTMLファイルのキャッシュを防ぐにはどうすればよいですか?管理コンソールからIISにアクセスすることはできません。

現在調査中のオプションは次のとおりです。

IISは、.NET framework 4を備えたバージョン7.5です。

27
Andrew

以下をweb.configソリューションに追加すると、Chrome、IE、Firefox、および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を要求するときに、そのno-cacheヘッダーがindex.htmlに設定されます。

37
Andrew

.NET Coreの場合、以下を使用しました。

        app.UseStaticFiles(new StaticFileOptions
        {
            OnPrepareResponse = context =>
            {                   
                if (context.File.Name == "index.html" ) {
                    context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
                    context.Context.Response.Headers.Add("Expires", "-1");
                }
            }
        });

ASP.NETコアrc2でブラウザーキャッシュを無効にする方法

14
ttugates

Htmlファイルを提供するときに、ランダムなクエリ文字列を追加できます。これにより、ファイルがブラウザキャッシュにある場合でも、ブラウザは古いバージョンを使用できなくなります。

/index.html?rnd=timestamp

もう1つのオプションは、IISレベルでno-cache設定を追加することです。これにより、ブラウザにファイルをキャッシュしないように指示する応答にCache-Control:no-cacheが追加されます。 IIS 7以降で動作します。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- Note the use of the 'location' tag to specify which 
       folder this applies to-->
  <location path="index.html">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>
6
govin
  <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
5
Sagar Jadhav

以下をweb.configソリューションに追加すると、Chrome、IE、Firefox、およびSafariで機能しました。

これにより、index.htmlを要求するときに、そのCache-Controlヘッダーがno-cacheに設定されます。

0
Shubham