Skip navigation

Monthly Archives: December 2009

What does browser caching means? Answer is save a copy of the web page  visited by the browser for a temporary period.So that any further  access to the same web page does not require the browser to repeatedly collect all the content from the webserver again.But This tends to create problem in case of Dynamic website where content tends to change in minutes time (or even in seconds time).  With browser cache enabled there might be chances that the old content is shown in the same page wheres the previous content has already been updated. There are two ways you can prevent a browser from caching a web page.

1. Meta tags

We use the following lines of htl code to prevent the browser from caching.

<meta http-equiv="expires" content="Fri, 05 Dec 2008 01:00:00 GMT"/>
<meta http-equiv="pragma" content="no-cache" />

This tells the browser that the cached copy of the we page is already  out of date. hence the on reaching this tag the browser will prevent itself from caching the page. The http-equiv=”pragma” plays the same role but is guaranteed to work on different browsers.

2. HTTP Headers

The other way around would be through the dynamic scripting language (like PHP)  header functions (Cache-Control) as shown below.HTTP 1.1 compliant browsers.

<?php
header('Expires:
Fri, 05 Dec 2008 01:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
?>

Advertisements