Preventing a page from being cached in browser

There are times when we require that a page always get served from the server and not from the browser cache. We can use the HMTL following “META” tags to acheive this.

<meta http-equiv="Expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />

The “Expires” meta tag is used to specify the expiry date for the web page, setting it to ‘0’ means “NOW” so the new time this page is accessed the browser will try to get a fresh copy of it.
We can also expire the page in back date to prevent caching using GMT time

<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT" />

Pragma and Cache Control are specifically designed to prevent (or control) caching, and should take a value of “no-cache”.

If PHP we can set the http response headers to prevent client browser or any proxy caches between the server and the client browser in the following way:

<!--?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?-->

Leave a Comment

Back to top