Showing posts with label caching. Show all posts
Showing posts with label caching. Show all posts

Saturday, April 4, 2009

Preventing caching of webpage

working on dynamic web pages you may come across a situation where one might start cursing the
web browser back button, because the the obsolete (in that context) page data might become a headache for you.
when i started finding solution to such issue to me java script was the first choice for me, just clearing the browser history using history.go(-1), but for more better approaches i got information about the use of meta tag for that purpose.

the two types are PRAGMA NO-CACHE and cache-control

as all meta tags are required to added in header
i.e
<html>
<head>
meta tags here!
</head>
</html>

try this :
<meta equiv="PRAGMA" content="NO-CACHE">
or
use with:
<meta equiv="PRAGMA" content="NO-CACHE">
<meta equiv="Expires" content="-1">


if doesn't work try the cache control tag
<meta equiv="CACHE-CONTROL" content="NO-CACHE">
if things don't come your way this will surely work for asp.net pages:

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()

Resources:
http://support.microsoft.com/kb/222064
Caching Tutorial
ASP.Net forum post