How do you disable caching on Modal dialogs in IE? - html

We have implemented a popup window as a modal dialog using the IE method:
window.showModalDialog('...aspx')
The target of the popup window is itself an ASP.Net web page.
Assume for the following steps that the popup has never been launched:
Launch popup.
Page_Load event handler executes on server side.
Close popup.
Immediately launch popup again.
This time Page_Load event handler doesn't execute.
It's clear that the popup content is being cached because if at Step 4 we clear the temporary internet files the Page_Load event handler is executed the second time.
We have experimented with adding the following to the Head of the web page (as recommended by several other sources) but none of it seems to work.
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
We have also seen places where the use of these is discouraged
Can anyone help?

Add a timestamp querystring variable to the URL of the dialog content - number of ticks since 1/1/08 or something - IE will treat it as a new page and ignore the cache.

To clear cache add this in page load:
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Given that the http-equiv directives don’t work (and arguably shouldn’t be used), and despite it unfortunately being in the hack category of solutions, I think we are going to have to go with this (posted by Greg)...
url = "<Some url with query string>"
var date = new Date();
window.showModalDialog(url + “&” + date.getTime(), ... );
It is strange that there is no definitive way to disable caching on these modal dialogs. I’m not sure whether using modal dialogs in web browsers is accepted as a "good idea" or not, but we are aware of at least some of the shortcomings and alternatives, but are just unfortunately unable to use them in this project.
Thanks for your suggestions.

Place Fiddler in between the IE and your server. Then check if the response to your request carries a HTTP header Cache-Control. Is there some value given other than no-cache ? If so then maybe IE will give this header priority over your http-equiv directive.
If not, you should try to make the server send the HTTP header Cache-Control:no-cache. If IE does not respect this, it's a bug in IE. Experience shows it's less painfull to opt for a different solution than to press for a bugfix, so in this case I'd agree to the tip of Greg.

First i tried by using the following code.
meta http-equiv="Cache-Control" content="no-cache"
meta http-equiv="Pragma" content="no-cache"
meta http-equiv="Expires" content="-1"
but it was not given any solution after, i tried with Query String with time stamp variable,
like
vat time = new Date().getTime();
url?queryString&time=time
then it works....
Thanks...

you forgot a tag to reprocess the page.
<base target="_top" />
if you put below tags, the cache will be cleaned:
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<base target="_top" />

One of the strange quirks of IE is that setting no-cache at the beginning of the file doesn't seem to work, but moving that section to after the original HTML often does. Still best to send it as an HTTP header, but the following will work in most cases:
<html>
<head><title>Blah</title></head>
<body>Contents</body>
</html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
</head>
</html>

The answer Response.Cache.SetCacheability(HttpCacheability.NoCache); is the only one that works correctly with IE9. If you set the timestamp in the querystring, you still have to refresh the page to get a different URL. So, the modal dialog is still cached until the page is refresh, unless you use Response.Cache.SetCacheability(HttpCacheability.NoCache);
Using a timestamp on the URL and Response.Cache.SetCacheability(HttpCacheability.NoCache); would be best, cover all the bases. It is IE we're dealing with after all.

You could also try the following statement at the top of the aspx page being called:
<%# OutputCache Location="None" %>

Related

IE11 caching breaking status page

I have a status page that needs to be constantly refreshed. It makes ajax calls to a Java server and gets the updated statuses. It works perfectly in Chrome, but in IE11 it is not refreshing when I click refresh. However, when I open the dev tools, it does work. As soon as I close dev tools, it stops working. I have the following meta tags in my head:
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
And it won't be enough to set my own browser to not use caching; I need it to work for users without them having to change their browser settings.
According to this, https://support.microsoft.com/en-us/kb/234067, there is a bug in IE around this. https://support.microsoft.com/en-us/kb/222064 explains it. Maybe you're hitting that? I would also say you should make sure your meta tags are at the top of the head section.
Alternatively, I think the best solution would be to use HTTP headers. I've had very good results with cache HTTP headers.
I found a solution: Apparently, IE caches ajax calls, so that needs to be disabled. Adding 'cache: false' to the ajax call fixes the issue:
$.ajax({
url: www.url.com,
cache: false
})

Force browser cache clearance across all browsers

I have the following code on my (all html webpages) :
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
However, this is not clearing up caches and my code updates are not showing up. Is there another way to accomplish cache refresh?
It is better to use standard HTTP headers to control the caching from the server side, rather than using the http-equiv meta tags in your HTML. It allows for controlling proxy caching and other intermediaries, making it a lot more effective. The meta tags also don't help if you have external CSS and JS files. These will still be cached, which may explain why it isn't working correctly for you. You would have to append a randomly generated query string to your resource paths so that the browser appears to be loading a brand new resource every time.
The http-equiv values above are actually not in the HTML 5 specification, so are not valid. You can read more on using HTTP headers correctly in this useful caching guide.

How to prevent caching in Google Chrome with meta tags

Is it possible to prevent caching files in Google Chrome programmatically?
I'd like to achieve the same effect as the option "disable cache" in chrome developer tools.
Main problem is that I'm using external script (it can't be changed by me) which loads another script - putting additional (randomly generated) parameters into source url for that script won't help.
So far I've tried to use meta tags:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1990 12:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
After testing with different combinations of that tags I can only say that Google Chrome ignores that at all.
Is there any option to do that?
Thanks in advance.
You could try to use the HTTP response headers, instead of HTML meta tags: see Disabling browser caching for all browsers from ASP.NET.
If you're asking about disabling the caching of data in input elements, see How to prevent google chrome from caching my inputs, esp hidden ones when user click back?

Google Chrome does not honor cache-policy in page header if the page is displayed in a FRAME

No matter what I do:
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="Fri, 30 Apr 2010 11:12:01 GMT" />
<meta http-equiv="Expires" content="0" />
<HTTP-EQUIV="PRAGMA" CONTENT="NO-STORE" />
Google Chrome does not reload any page according to the page's internal cache policy if the page is displayed in a frame. It is as though the meta tags are not even there. Google Chrome seems to be ignoring these tags.
Since I've gotten answers to this question on other forums where the person responding has ignored the operative condition, I will repeat it: this behavior occurs when the page is displayed in a frame.
I was using the latest released version and have since upgraded to 5.0.375.29 beta but the behavior is the same in both versions.
Would someone please care to confirm one way or another the behavior you are seeing with framesets and the caching/expiration policies given in meta tags?
Thanks
Did you try those meta tags in both the framed document as well as the parent/hosting document?

Is there a <meta> tag to turn off caching in all browsers? [duplicate]

This question already has answers here:
How do we control web page caching, across all browsers?
(29 answers)
Closed 6 years ago.
I read that when you don't have access to the web server's headers you can turn off the cache using:
<meta http-equiv="Cache-Control" content="no-store" />
But I also read that this doesn't work in some versions of IE. Are there any set of <meta> tags that will turn off cache in all browsers?
For modern web browsers (After IE9)
See the Duplicate listed at the top of the page for correct information!
See answer here: How to control web page caching, across all browsers?
For IE9 and before
Do not blindly copy paste this!
The list is just examples of different techniques, it's not for direct
insertion. If copied, the second would overwrite the first and the
fourth would overwrite the third because of the http-equiv
declarations AND fail with the W3C validator. At most, one could have
one of each http-equiv declarations; pragma, cache-control and
expires. These are completely outdated when using modern up to date browsers.
After IE9 anyway. Chrome and Firefox specifically does not work with these as you would expect, if at all.
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Actually do not use these at all!
Caching headers are unreliable in meta elements; for one,
any web proxies between the site and the user will completely ignore
them. You should always use a real HTTP header for headers such as
Cache-Control and Pragma.
According to Independent Security Evaluators' great case study on the industry-wide misunderstanding of controlling caches, only Cache-Control: no-store is recognized by Chrome, Firefox, and IE. IE recognizes other controls, but Chrome and Firefox do not.
It doesn't work in IE5, but that's not a big issue.
However, cacheing headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.
pragma is your best bet:
<meta http-equiv="Pragma" content="no-cache">
I noticed some caching issues with service calls when repeating the same service call (long polling). Adding metadata didn't help. One solution is to pass a timestamp to ensure ie thinks it's a different http service request. That worked for me, so adding a server side scripting code snippet to automatically update this tag wouldn't hurt:
<meta http-equiv="expires" content="timestamp">
Try using
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">