How To Prevent Browser Caching of HTML Pages
By Angsuman Chakraborty, Gaea News NetworkSaturday, 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.
November 5, 2006: 5:23 am
Right out of wordpress: [code]function nocache_headers() { 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. |
war59312