One solution would be to add a QueryString variable to the url that is a random guid, but that seems a little messy. Is there a setting somewhere that will prevent the browser from displaying a cached version of a page?
views:
430answers:
6Hi Slim, ONE aproach would be to add an 'Expires or a Cache-Control Header'.
This has been extracted from Yahoo Best Practices (http://developer.yahoo.com/performance/rules.html)
There are two things in this rule:
* For static components: implement "Never expire" policy by setting far future Expires header
* For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests
Browsers (and proxies) use a cache to reduce the number and size of HTTP requests, making web pages load faster. A web server uses the Expires header in the HTTP response to tell the client how long a component can be cached. This is a far future Expires header, telling the browser that this response won't be stale until April 15, 2010.
Expires: Thu, 15 Apr 2010 20:00:00 GMT
If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.
ExpiresDefault "access plus 10 years"
So essentially you will be able to set the expiry date to 'inform' the browser that cached component has expired. Therefore the browser will go and request for the site again.
Assuming you need this for web development, another way would be to force clear the cache. on Firefox, this can be done through CTRL + F5 or CTRL + SHIFT + R.
Hope this helps, Lucas
You can add a meta-tag like this.
<meta http-equiv="pragma" content="no-cache" />
In our ASP.Net projects we create a BasePage all other pages inherit from. In the base page we have a function
Public Sub DisableCaching()
With Response
.Expires = 0
.ExpiresAbsolute = Date.Today.AddDays(-1)
.AddHeader("pragma", "no-cache")
.AddHeader("cache-control", "no-cache")
End With
End Sub
We call that on any page we don't want cached.
One solution would be to add a QueryString variable to the url that is a random guid, but that seems a little messy
Why messy? It's the most reliable way. It is not necessary guid, it could be current time.