Page 1 of 1

Automatic refresh page

Posted: Fri 16 Apr, 2004 22.34
by Larry Scutta
I have a website with a couple of pages that get updated fairly regularly. It's quite inportant that users see the updated pages rather than old versions.

Anyone know of a bit of code that I can put on the pages that will force the browser to get the page from the server rather than the cache?

Posted: Sat 17 Apr, 2004 00.26
by Neil Jones
It's not really possible to do it from a HTML page I wouldn't have thought, you really need to force the pages to expire thorough server side methods such as PHP.

If you have PHP, this should work:

Code: Select all

<?php
header ("Expires: Mon, 5 March 2001 13:30:35 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
?>
This needs to go BEFORE anything (HTML or whatever) is sent to the brower.

So something like this crude example in your *.php file:

Code: Select all

<?php
header ("Expires: Mon, 5 March 2001 13:30:35 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
?>

<html>
<head>
<title>Title</title>
</head>
<body>
<p>This is my web page</p>
</body>
</html>

Posted: Sat 17 Apr, 2004 00.36
by James Hatts
You could simply use this meta tag in the header:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

Posted: Sat 17 Apr, 2004 00.41
by Neil Jones
James Hatts wrote:You could simply use this meta tag in the header:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
Yes, but not guaranteed either. Number of sites I see with that Meta tag and IE still pulls the page out the cache.

I think the ultimate way to do it is to set IE and other browsers to check for new versions of pages every time. But IE has always favoured the cache where possible regardless of what you tell it otherwise.