Automatic refresh page

Post Reply
Larry Scutta
Posts: 48
Joined: Tue 16 Sep, 2003 00.52

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?
Neil Jones
Posts: 661
Joined: Thu 11 Sep, 2003 20.03
Location: West Midlands

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>
James Hatts
Posts: 309
Joined: Sat 16 Aug, 2003 23.34
Location: London

You could simply use this meta tag in the header:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
Neil Jones
Posts: 661
Joined: Thu 11 Sep, 2003 20.03
Location: West Midlands

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.
Post Reply