【问题标题】:always need to disable\delete cache in google chrome总是需要禁用\删除谷歌浏览器中的缓存
【发布时间】:2017-11-02 11:03:07
【问题描述】:

我正在开发一个 Web 应用程序、带有 ASP.NET 的服务器和 AngularJS 中的前端,每次我在 Azure 应用服务(IIS 即服务)上部署新版本时,我都会遇到缓存问题 -在我打开 chrome 开发人员工具中的禁用缓存复选框或按 Ctrl+Shift+R

之前,视图不会更新到新版本

我尝试在 index.html 中添加这个元标记

<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

但它不起作用。 我尝试了很多在网络上找到的想法,但问题没有解决

【问题讨论】:

  • 是 html 还是 javascript 缓存?

标签: asp.net google-chrome caching


【解决方案1】:

我认为这已经被问过(或类似的),来源:Disabling browser caching for all browsers from ASP.NET

我发现对我有用的这个线程的解决方案是将其添加到您的页眉中:

<script language="javascript" type="text/javascript">
    window.onbeforeunload = function () {   
    // This function does nothing.  It won't spawn a confirmation dialog   
    // But it will ensure that the page is not cached by the browser.
}  

【讨论】:

    【解决方案2】:

    有一个静态内容的IIS配置来设置缓存模式和过期时间:

    <configuration>
       <system.webServer>
          <staticContent>
             <clientCache cacheControlMode="UseExpires"
                httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
          </staticContent>
       </system.webServer>
    </configuration>
    

    然后,如果您将检查请求到服务器以获取JSHTML 文件,将出现几个标题:

    回复:

    • ETag 用于缓存条目的键
    • Last-Modified此文件的最后修改日期

    请求:

    • If-Modified-Since 此文件的最后修改日期 - 如果文件的最后修改日期与指定日期不同,则从服务器获取文件
    • If-None-Match 缓存键的 ETag - 如果最后修改日期与指定的日期没有差异,则从此缓存键中获取文件

    【讨论】:

      猜你喜欢
      • 2015-11-01
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 2011-03-23
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      相关资源
      最近更新 更多