deandob
deandob

Reputation: 5280

Visual Studio Express 2012 Web debug randomly not refreshing browser cache with changes

Been using Visual Studio Express 2012 Web for a few weeks now learning JavaScript, HTML5 and CSS for a web based application. As a .NET developer its great to have the familiarity of VS (although better JS/HTML intellisense would be nice) and my progress is good, however there is an annoying VS quirk during debugging that I can't resolve. Occasionally VS (or perhaps more specifically IE10) will stop recognizing any code changes and run the previous version of the code. This is annoying but I can get around it by hitting an extra F5 when IE10 launches but it shouldn't be needed. I assume the file cache for IIS express is not being refreshed when the source is updated but I could be wrong. After a while of experiencing this problem I have not been able to pick up a pattern to understand what usage pattern causes the problem.

Has anyone else seen this? Any fixes? Searching the net draws a blank.

I use VS web site project types and have a vanilla installation of VS 2012 express (uses IIS express) on Windows 8 and debugging with IE10.

Thanks.

Upvotes: 0

Views: 3190

Answers (3)

Bart
Bart

Reputation: 5203

I am using Chrome myself, but still experienced the same problem. In the end I settled on the solution of completely turning caching OFF on my local WebServer - being VS's IIS Express -. This can be done by adding a UseMaxAge of 0 to the web.config. As follows:

XML
<configuration>
  ...
    <system.webServer>
      ...
      <staticContent>
        ...
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:00:00" />
      </staticContent>
  </system.webServer>
</configuration>
Notes
  • This works in regular/full IIS as well.
  • Be sure NOT to deploy this setting to PRODUCTION. Use a production specific web.config there to allow end users to harness some caching :). Otherwise this could be a performance killer.
  • Using CTRL+F5 instead of just F5 SHOULD also refresh it, however that somehow did not work either Chrome v39.0.2171.71 m). I found out it DID work to directly open the cached Javascript URL in the same browser (!) tab, press Ctrl+F5 on that and then return to the (HTML) page and use CTRL+F5 there again.
  • Another option that sometimes works is to restart IIS Express (Taskbar right click and choose 'Exit' from context menu). But that is also pretty cumbersome.. :)

Upvotes: 0

Alexander Chernosvitov
Alexander Chernosvitov

Reputation: 698

Add this:

window.applicationCache.addEventListener('updateready', function (e)
{
  if (window.applicationCache.status == window.applicationCache.UPDATEREADY)
  {
    window.applicationCache.swapCache();
    if (confirm('A new version of this site is available. Load it?'))
     window.location.reload();
  }
}, false);

I found this solution somwhere in the Net. Sorry, but I don't remember the author. It works for me when I debug Web App with JavaScript in Visual Studio 2012 using IE. Please, stop cursing Microsoft. We all use their pruducts, be fair. I don't work at Microsoft but I would be unhappy without its products. I think all of us would.

Upvotes: 1

deandob
deandob

Reputation: 5280

Has any web developer using visual studio web found a way around this? I found Chrome to be more reliable at ensuring the cache is refreshed when the code changes however with the IE & VS integration its easier to develop with IE.

This must be a common problem? I have tried IIS Express as well and the same issue (figures as I'm sure its a problem with the browser cache). Typically the problem occurs when running IE for the first time, and if there is a bug in my Javascript code that breaks the execution before the screen is painted its quite a pain as its not as easy to clear the cache manually. The only workaround I have is use F12 and 'clear browser cache for this domain' then F5 to refresh. Workable but annoying.

Any tips to resolve this would be appreciated

Upvotes: 1

Related Questions