自动刷新浏览器缓存 [英] Refresh browser cache automatically

查看:108
本文介绍了自动刷新浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我以前从未处理过的事情,如果我听起来一无所知,请原谅。

This is something I've never had to deal with before so excuse me if I sound ignorant.

我遇到的基本问题是在内部工作时在Visual Studio 2010中,我所做的任何更改似乎都被某种高速缓存捕获了。

The basic issue I'm having is that while working within Visual Studio 2010 any changes I make seem to be caught in some sort of cache.

例如,我将对页面进行更改,运行解决方案,然后然后我必须按Ctrl + F5强制刷新缓存以查看更改。这是使用ASP.NET/HTML/CSS& JavaScript代码。一样。

For example, I'll make a change to a page, run the solution, and then I have to press Ctrl + F5 to force refresh of cache to see the changes. This is with ASP.NET/HTML/CSS & JavaScript code. Same thing.

过去,Visual Studio每次运行时都只清除缓存,所以至少我有点沮丧。

In the past Visual Studio used to just clear the cache every time I ran, so I'm a little frustrated to say the least.

此外,当我将解决方案部署到IIS服务器时,用户也会发生同样的事情。即使ASP.NET页上进行了更改,用户仍会继续拉出缓存的版本,直到清除缓存为止。我通过使用版本号重命名文件(尤其是javascript)在某种程度上减轻了这个问题,因此客户端始终将它们视为新文件并加载而不是从缓存加载。

Additionally, when I deploy the solution to a IIS server, the same thing happens for users. Even though a ASP.NET page had changes on it, the users keep pulling up a cached version until they clear their cache. I've mitigated this issue to a degree by renaming the files (especially javascript) with version numbers so the client always sees them as a new file and loads instead of loading from cache.

在Visual Studio或web.config中是否存在任何可能引起此问题的设置?

Is there any settings within Visual Studio or web.config that could be causing this?

编辑:这是我的web.config文件

Here's my web.config file

<configuration>
  <system.web>
    <sessionState cookieless="UseCookies" timeout="1440" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"/>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx"/>
      </assemblies>
    </compilation>
    <authentication mode="Windows"/>
    <pages>
      <controls>
        <add tagPrefix="ajaxtoolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolKit"/>
      </controls>
    </pages>
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="50000000"/>
      </webServices>
    </scripting>
  </system.web.extensions>
</configuration>


推荐答案

Web资源(Css,Js,Images甚至是HTML) )需要花费一些时间通过网络下载,这会增加加载网页所需的时间(史蒂夫·苏德斯(Steve Souders建议,将近80%的时间,请参见此处)。 HTTP缓存允许这些资源由浏览器或代理保存或缓存。一旦缓存了资源,浏览器或代理就可以引用本地缓存的副本,而不必在后续访问网页时再次下载。

Web resources (Css, Js, Images and even Html) take time to download over the network, which increases the time it takes to load a web page (Steve Souders suggests it takes nearly 80 %, see here) . HTTP caching allows these resources to be saved, or cached, by a browser or proxy. Once a resource is cached, a browser or proxy can refer to the locally cached copy instead of having to download it again on subsequent visits to the web page.

浏览器缓存可以由HTTP控制缓存标题(请参见快速概述此处

Browser cache can be controlled by HTTP Cache Headers (see a quick overview here)

所以,这不是因为Visual Studio或asp.net,而是因为浏览器。

So, it's not because of Visual Studio or asp.net, but because of the browser.

希望,有很多方法可以在服务器端禁用缓存(仅出于测试目的)

Hopefully, there are many ways to disable cache at server-side (just for testing purpose) or on client side (to relaod and bypass the cache).

以下是一些可能性:

使用asp.net >

您可以使用此代码显式禁用浏览器缓存

You can explicit disable browser cache with this code

// Stop Caching in IE
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

// Stop Caching in Firefox
Response.Cache.SetNoStore();

警告:仅在本地进行测试!

此外,许多捆绑系统允许您控制缓存设置。
asp.net mvc捆绑包设置了从捆绑包创建一年起的HTTP Expires标头,并在查询字符串中添加了一个法则参数。只要捆绑包不变,此唯一标识符就是相同的。请参见此处

Also, Many bundling systems allow you to control cache settings. asp.net mvc Bundles set the HTTP Expires Header one year from when the bundle is created and add an additionnal parameter in the query string. As long as the bundle doesn't change, this unique identifier will be the same. See here.

在浏览器上

有很多快捷方式可以重新加载页面并绕过缓存:
例如:

There are many shortcuts to reload a page and bypass the cache: For exampel :


  • Chrome :Shift + Reload Button

  • IE :Ctrl + F5或Ctrl +重新加载按钮

  • Firefox :Ctrl + Shift + R或Shift +重新加载

  • Chrome : Shift + Reload Button
  • IE : Ctrl + F5 or Ctrl + Reload Button
  • Firefox : Ctrl + Shift + R or Shift + Reload

还有很多方法可以完全禁用浏览器上的缓存。

Also there are many ways to completely disable cache on browser.


  • IE :工具‣Internet选项‣Internet临时文件‣设置‣检查存储页面的新版本

  • Chrome :工具‣开发人员工具‣左下角的齿轮图标‣角禁用缓存

  • Firefox :工具‣选项‣高级‣网络‣缓存大小= 0

  • IE : Tools ‣ Internet Options ‣ Temporary Internet files ‣ Settings ‣ Check for a new version of stored pages
  • Chrome : Tools ‣ Developer Tools ‣ cogwheel icon in lower left ‣ corner Disable Cache
  • Firefox : Tools ‣ Options ‣ Advanced ‣ Network ‣ cache size =0

维基百科上有一个很棒的列表

这篇关于自动刷新浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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