How To Prevent Browser Caching of HTML Pages

By Angsuman Chakraborty, Gaea News Network
Saturday, November 4, 2006

This is old news for most of us and yet when I wanted to quickly find it, it took some searching. So here it is, in simple language, what you can do to prevent your web pages from being cached by browsers.

Add in your head section (between <head> and </head> tags):

<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">

And then add the same code just before the ending </html> tag:

<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">

Explanation:
The Pragma directive is to satisfy most browsers. However Internet Explorer doesn’t work with it at the beginning, so we have to place it at the end too. Again IE 5.5 doesn’t recognize it. So we need to add the Expires directive too. Hat tip

Note: In WordPress you can call the function nocache_headers() to prevent caching by modifying HTTP headers, as dicussed in the comments below.

Discussion
November 5, 2006: 5:23 am

Right out of wordpress:

[code]function nocache_headers() {
@ header(’Expires: Wed, 11 Jan 1984 05:00:00 GMT’);
@ header(’Last-Modified: ‘ . gmdate(’D, d M Y H:i:s’) . ‘ GMT’);
@ header(’Cache-Control: no-cache, must-revalidate, max-age=0′);
@ header(’Pragma: no-cache’);
}[/code]

Works well for me. :)

November 4, 2006: 7:57 pm

The link is highlighted (semi-bold) for viewers who haven’t browsed that link before (within their browsers history expiry time). Thanks for the tip.

November 4, 2006: 11:28 am

Hey, not that this is really my business, but the link in my above comment is really hard to pick out. You might want to make it red (like the other links on the page) or at least underlined.

November 4, 2006: 11:28 am

I definitely recommend using http headers over meta tags. See guide.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :