RSS

Stop pages from being cached

17 Jun

Here is a way using javascript:

<html>
<head>
<title>Page Title</title>

<script language="javascript"> <!--
// this code and associated form is to workaround
// a bug in Internet Explorer  that will show a cached version
// when the back button is used. the reload is not
// triggered by Netscape since it properly never gets
// the page from the cache.
function onload_reloadme () {
  if (document.reloadme_form.reloadme_field.value == "reloadme" ) {
    self.location.reload(true)
  } else {
    document.reloadme_form.reloadme_field.value = "reloadme";
  }
// set the focus to the first non-hidden field on the second
// form - the first form is always the reloadme_form below.
  if (document.forms[1]) {
    for (i=0; i<document.forms[1].elements.length; i++) {
      if (document.forms[1].elements[i].type.toLowerCase() != "hidden") {
        document.forms[1].elements[i].focus();
        break;
      }
    }
  }
}
// -->
</script>

<!-- Yes, I know <FORM> is not proper inside <HEAD>, but it seems
 to work OK and avoids a blank line that most browsers put
 around <FORM>s. -->

<form name="reloadme_form"><input type=hidden name="reloadme_field" value="dontreloadme"></form>

</head>

<body onLoad="onload_reloadme()">

<p>Sample Page

</body>
</html>

Here is another way using php:

header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

Here is another way by modifying the meta tags:

Include this META tag in the HEAD section of your page along with the other META tags:
<meta http-equiv='Pragma' content='no-cache'>
microsoft browsers require this additional meta tag as well
<meta http-equiv='Expires' content='-1'>

and then include this second HEAD section between your BODY closing tag and HTML closing tag:
(add this extra section if you find your pages are still being cached in some browsers)

</body>
<head>
<meta http-equiv='Pragma' content='no-cache'>
</head>
</html>

Here is another way:

Just place this in individual form fields or in the form tag itself:
autocomplete=”off”

Advertisements
 
Leave a comment

Posted by on June 17, 2011 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: