Automatically update browser cache

This is something that I never had to face before excusing me if I sound ignorant.

The main problem that I am facing is that when working in Visual Studio 2010, any changes that I create seem to be caught in some kind of cache.

For example, I will make a change on the page, run the solution, and then I need to press Ctrl + F5 to force update the cache to see the changes. This is with ASP.NET/HTML/CSS and JavaScript code. Same.

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

Also, when I deploy the solution to the IIS server, the same thing happens for users. Although there have been changes to the ASP.NET page, users continue to upgrade the cached version until they clear their cache. I mitigated this problem to an extent by renaming files (especially javascript) with version numbers so that the client always sees them as a new file and loads them instead of downloading from the cache.

Are there any settings in Visual Studio or web.config that might be causing this?

EDIT: Here is 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> 
+4
source share
1 answer

Web resources (Css, Js, Images, and even Html) require time to download over the network, which increases the load time of a web page (Steve Suders suggests that it takes up almost 80%, see here ). HTTP caching allows you to save or cache these resources with your browser or proxy server. After caching the resource, the browser or proxy server may link to the locally cached copy instead of having to download it on subsequent visits to the web page.

Browser cache can be controlled using HTTP cache headers (see brief description here )

So, this is not because of Visual Studio or asp.net, but because of the browser.

We hope that there are many ways to disable the cache on the server side (for testing purposes only) or on the client side (to convince and bypass the cache).

Here are a few possibilities:

Using asp.net

You can explicitly disable browser cache with this code

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

Warning: do this only locally for testing purposes!

In addition, many binding systems allow you to control cache settings. Asp.net mvc packages set the HTTP Expires Header header a year after creating the package and adding an additional parameter to the query string. Until the package changes, this unique identifier will be the same. See here .

In browser

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

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

There are also many ways to completely disable the cache in the browser.

  • IE : Tools ‣ Internet Options ‣ Temporary Internet Files ‣ Settings ‣ Check for a new version of saved pages
  • Chrome : tools ‣ developer tools ‣ gear icon in the lower left corner Disable cache
  • Firefox : Tools ‣ Options ‣ Advanced ‣ Network ‣ Cache size = 0

Wikipedia has an excellent list .

+5
source

Source: https://habr.com/ru/post/1484836/


All Articles