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?
I'm having some trouble trying to prevent my page from caching using the cache-control parameters in the HTML header. Below is a sample HTML code which I've created for testing purposes. I can't seem to figure out what I'm missing though, or perhaps I'm misunderstanding how all this cache-control really works. I would appreciate if someone could help me figure out what I am doing wrong.
Sample HTML:
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
</head>
<body>
Test Html
</body>
</html>
I apologize for the link, but I'm not allowed to post pictures yet. When I view "chrome://cache", I see the cached page in the list of cached items. Clicking on it, I am able to view the actual content itself.
Chrome's cache
From my understanding, using the no-cache or no-store should prevent the page from appearing in Chrome's cache. Is this assumption correct?
Thanks in advance.
Heng
I'm using a content editor web part to pull/display a html file that lives in a SharePoint library, is there any way i can prevent the page (html or SharePoint) from caching?
I have tried the following in the html file with no luck:
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
I dont know if this help you or not but..
Try to add ? at the end of your content link
Let me know if this help you or not.
Thanks
I'm writing a simple web page that shows the status of my server, and therefore must always be loaded from the server, and not from the cache.
How do I make it happen? I've tried
<head>
<meta http-equiv="expires" content="0">
<title>status</title>
</head>
But it only works with Chrome. Any ideas about Firefox?
Have you tried:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
This has worked for me in the past to resolve Firefox caching issues.
Source: http://www.i18nguy.com/markup/metatags.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" %>