Reputation: 2615
Hello I got a question regarding no caching within my .net web application. I got an XHTML web application which is running with the following metatags:
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
I want to make this application a HTML5 valid application. After running it through the HTML5 validator it will output that those metatags are not valid.
I did some research on the internet and a lot of people suggest to use a manifest file like:
CACHE MANIFEST
# 2016-03-18 time 10:30 UTC v 1.01
NETWORK:
*
Where this basically says: for all files, do not read from cache but from network server. This sounds like the browser is not caching it at all. But a downside of this approach is that as been said in this post that you need to update the manifest file each time you do a (partial) postback. Which does not sound a very nice proper way to do that.
So I searched for an alternative method by using HTTP headers through my IIS via web.config
adjustments. I found a source that says that you can use the following method:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
No I am wondering is this method a good approach in order to not cache my webapplication?
Upvotes: 0
Views: 4900
Reputation: 723
CACHE MANIFEST is for offline web apps and it's not an easy stuff to use at all, and as far as I know isn't even recommended way to make offline apps.
If you don't want your page to be cached in browser, then configuring response headers would be the right approach.
To prevent browser from caching a page completely, you can set following headers:
Cache-Control:no-store
Cache-Control:no-cache
Pragma:no-cache
Expires:Fri, 18 Mar 1999 12:22:21 GMT
Note that Pragma header is for HTTP 1.0, and Cache-Control:max-age is equivalent to Expires, but Cache-Control:max-age has higher priority, so there is no reason to have them both of them simultaneously
Upvotes: 1
Reputation: 12943
Use the manifest file as you described, and update it with javascript:
Your manifest:
CACHE MANIFEST
# 2016-03-18 time 10:30 UTC v 1.01
NETWORK:
*
Javascript:
var appCache = window.applicationCache;
appCache.update();
A good start to use appcache: A Beginner's Guide to Application Cache
Upvotes: 0