Last post Jan 19, 2018 09:00 PM by DA924
Nov 17, 2016 06:51 PM|KbCb|LINK
When debugging an ASP.NET MVC (SPA) application, I used to be able to make changes to the .js files and .html files that were served by IIS Developer Express and just simply refresh the browser to see the changes. For a while now, it seems that IIS Developer
Express has not recognized the changes to the file system, and doesn't show a different "Last-Modified" date when the browser performs GET requests for the .js and .html files. So, in most cases, the browser uses the cached version of the .js and .html files
because it thinks the files haven't changed. I have gotten around this for the most part by referencing the .js and .html files with an extra query parameter (ex: /scripts/myscript.js?2342344322234) so that the browser always sees it is a new (un-cached) request.
However, this isn't very efficient for a number of reasons, including the fact that Visual Studio doesn't recognize the file in the editor, so breakpoints don't get hit.
What do I need to do to get VS (or IIS Express) to recognize changes and respond appropriately with the correct "Last-Modified" date?
Nov 17, 2016 07:12 PM|senthilwaits|LINK
The browser is caching the files. Press Ctrl+F5 or Ctrl+R to force the browser to GET the files from the server whenever there is a change.
Nov 17, 2016 07:29 PM|KbCb|LINK
I know the browser is caching the files. Pressing Ctrl+F5, or Ctrl+R doesn't work in internet explorer and chrome...
Nov 18, 2016 02:38 AM|Jean Sun|LINK
You can try disable the browser's cache or use private window. Below are some links for you reference.
How to Completely Disable Cache in Google Chrome
Internet Explorer Always refresh from server
How to start private browsing in Internet Explorer, Firefox, Opera, Chrome
Nov 18, 2016 09:13 AM|Stewa11|LINK
I know in IE there is a setting to always check for latest version of files. Look for the same in Chrome.
There is also an old trick/workaround way of time stamping the cache so that it always refreshes. Let me know if you need this and I will look for the code.
Nov 18, 2016 09:11 PM|KbCb|LINK
Thank you for the comments. However, none of these solutions are addressing the actual problems. I don't want to just force the browser to always refresh or make this a manual operation. What I don't understand is why .NET (or VS or IIS Dev Express) is not
recognizing that the file(s) has changed and appropriately updated the "Last-Modified" header of these files when the browser requests a GET for them... None of this would be an issue if .NET/VS/IIS properly used the functionality baked into the HTTP standard.
Nov 22, 2016 07:40 AM|Jean Sun|LINK
IIS Express just receives the request and response the related content to client.
When the client requests for some resource, it first check the cache, if the resource can be find in cache file, it will not request the server any more. So the cached file will not be updated. The Last-Modified Header is not read when the resource exists
The things you can do is to disable the cache in Web browser or add some header in your response to tell Web Browser not cache your files.
You can add the following code into your web.config, which will tell the web client not cache the files.
<clientCache cacheControlMode="DisableCache" />
More about client cache settings :
Dec 02, 2016 02:31 PM|neo_rahhh|LINK
I do not want to disable caching for any part of my application. Still I expect the browser to be smart enough making decision on picking the cached version of HTML or not. That means it should be able to detect that the content is changed or not. RIGHT
Dec 05, 2016 06:31 AM|Jean Sun|LINK
Still I expect the browser to be smart enough making decision on picking the cached version of HTML or not. That means it should be able to detect that the content is changed or not. RIGHT ??
Unfortunately, it seems that the web browsers are not smart enough to making decision on picking the cached version of request from server.
Web browsers will first check if the file is cached and check if the cached file is expired. If a valid cached file exists, web browsers will load the cached file instead of requesting server.
The ways to force the reload of some content:
1. The easiest way to force a reload is to hit the Ctrl-F5 shortcut when that page is open. This bypasses the cache and requests all files from the server. This is different from hitting F5 only which will also refresh the page. Doing so will check if new
versions of cached resources are available and if they are load them from the server. If there is no new version, the cached version will be loaded instead.
2. While this works well individually, you sometimes may want to disable caching completely. This can be done using Developer Tools again.
3. Last but not least, it is also possible to delete the disk cache completely or partially to force the browser to load all contents from the Internet.
May 24, 2017 11:29 PM|cogitaria|LINK
Think about the implications of your solution for visitors to your site. It should not take much thought to conclude that is not a practical solution in any way shape or form short of a work-around for a hopelessly broken web server.
May 24, 2017 11:56 PM|cogitaria|LINK
The question is not how to clear your browser cache, so you have not provided a solution. You seem to be of the impression that only visitors who press the magic key (F12...) ever get to see changed content. How is that not manifestly idiotic? The runner
up for non-solutions is the advice to set no-cache headers. Fantastic! You've now overloaded your server just in case something changes. How is that not obviously moronic?
Here's an idea Jean. You will find this is true by visiting any site with a real web-server. Unless the content had a specific cache header the browser will ASK whether or not what it has is current. The web-server can cheaply determine, based on nothing
more than the modification date, whether the file is changed. If it hasn't use the server cache, otherwise replace it with the updated content. Imagine that! Static content is cached until you modify the source file, at which point it updates. This would
be a great exercise for some sixth grade computer class.
Jan 19, 2018 04:52 PM|Wowotoe|LINK
I'm getting the same issue. I can confirm this is IIS Express cache issue, not browsers' cache. I tried to debug an ASPX webpage under VS 2017. Pressing ctrl-F5 and it brings up IE (my default). Changed the HTML contents of webpage, refresh the browser and
still seeing the old stuff.
I fired up Chrome/Firefox and try to load the same page served by IIS Express, which never opened in Chrome/Firefox before. And I'm seeing the old contents as well.
I also tried different method, F5 or Browser Link, same issue as well. I have to stop the website completely in IIS Express and relaunch it. Very frustrating.
I also found something interesting. I have two development machine (Win 7 & Win 10). This IIS Express cache issue doesn't not happen under Win 7. Only under Win10.
Jan 19, 2018 08:58 PM|bruce (sqlwork.com)|LINK
see the docs for configure:
the default for the static file handler is a cache max age, so a head request is not required.
when you use chrome for debugging, you can set disable cache when dev tools open.
Jan 19, 2018 09:00 PM|DA924|LINK
It's beyond me as to why IIS Express is even being used. I have never seen it used on any client's development machine. I don't even use IIS Express in my home development environment, which is no better than the VS Web developer trash that use to be part
of VS that IIS Express replaced.
I always have Web development projects through VS deployed to local IIS so that the solution can be run and debugged through Visual Studio against local IIS and eliminate IIS Express out of the picture.
To specify the Web server for a Web application project
One must start VS using Run As Administrator.
You can also try the IIS forum about IIS Express.