0

Visual Studio 2012 で ASP MVC シングル ページ アプリケーションを開発しています。静的 JS/CSS/HTML ファイルで構成され、必要に応じて読み込まれるコンポーネントを使用します。スタティックはブラウザによってキャッシュされるため、このアプローチは本番環境でのバンドルを必要とせずにうまく機能しますが、現時点で作業しているファイルを更新するにはキャッシュを無効にする必要があるため、dev に問題があります。つまり、約 100 を意味します。ページを更新するたびに小さな静的ファイルが読み込まれ、約 40 秒かかります。

私は現在 Chrome ワークスペースを調べていますが、より普遍的な実行可能な解決策は、変更日が過去 30 分以内のファイルのキャッシュを具体的に無効にすることだと思います。

VS / ASPで最近変更されたファイルのキャッシュを無効にする代替ソリューションまたは既存のコンポーネントを探しています(カスタムHTTPハンドラー?)。

4

1 に答える 1

-1

IIS または IIS Express を使用している場合、最も簡単な解決策は、web.configファイルに設定を追加して、開発環境でキャッシュを完全に無効にすることです。

注:web.configファイルがない場合は、Web サイトのルート ディレクトリに作成できます。

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

または、Web サイトの特定の場所にあるファイルのキャッシュを無効にすることもできます。

<configuration>
  <location path="path/to/the/file">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

いずれの場合も、テスト/実稼働環境でこれらのセクションを削除するために、リリース中にWeb 構成変換を使用できます。

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <!-- Use this section if you are disabling caching site-wide -->
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="Cache-Control" value="no-cache" xdt:Transform="Remove" xdt:Locator="Match(name)" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>

    <!-- Use this section if you are disabling per folder (duplicate if necessary) -->
    <location path="path/to/the/file" xdt:Transform="Remove" xdt:Locator="Match(path)">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>

参照: weserver 構成設定を使用して IIS 7 で個々のファイルのキャッシュを無効にする方法

于 2016-06-25T18:57:08.857 に答える