Cache Control : Making your web pages web-server friendly

Summary : The caching of your web pages on web servers can be customised to your own requirements.

Recommendation : There are countless reasons why you should invest a little time to make your web pages cache-friendly.


Web page caching Benefits of Caching Net links Web page settings Home


Web Page Caching - a summary

A few basics first need to be discussed to understand what the process of web-caching is.
First, we need to briefly cover how the web works. There are 3 main scenarios that happen whenever a web page is requested by a net surfer.



A summary...

So the web pages you request might not necessarily be derived from the actual website you are visiting. Instead the pages you visit might simply be pre-stored in the web cache of your local ISP for instance. Further still, the pages might be stored in the web cache on your computer. The next section deals with why the cache is very beneficial to both the web surfer and the webmaster.

Benefits of Caching

So far we have mentioned that the pages you visit don'nt necessarily originate from the website you are visiting. There are VERY important reasons why the internet has been designed this way.

Benefits to the website visitor

 - regularly visited pages (including images, files) that do not change in content, are cached on the local server, making access time quicker.


Webmaster benefits

- Internet Bandwidth can be greatly reduced, since the unchanged pages are not un-necessarily downloaded from the original web host. This reduced level of bandwidth can mean huge cost savings for the larger site.
- The demand on the web-host which supports the website will be less, leading to a much more faster and more smooth running web service.
- Since access time is likely to be faster, visitors are likely to stay on your site longer.


Web Page Settings

The following will be a summary guide to the options available for cache-control of your web pages.

There a number of ways that web pages can be set which tell the web server NOT to cache their pages, or 'how' to 'cache' the pages.

Using the Meta Variable - the HTTP equivilent.

The meta variable is comprised of 2 parts, the 'name' and the 'value'. It really is a very simple way of entering commands into the code of your web pages, commands that tell the web server how to cache your pages.

The 'Pragma' command and the 'no-cache' commands are often NOT much use, although a few web servers DO obey such commands.


Many websites use the following web cache control commands...

<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

or this....

<META Http-Equiv="expires" Content="wed, 6jan 2003 08:22:34 GMT"
<META Http-Equiv="pragma" Content="no-cache"
<META Http-Equiv="cache-control" Content="no-cache"
<META Http-Equiv="cache-control" Content="must-revalidate"

Personally, i am not too fond of the 'expires' command, i prefer the 'max-age' command, which seems simpler.
The following section gives some examples of what I consider to be the best web-caching command.


The best 'command' to control caching - 'cache-control'

You can see in the example below a typical method to control cacheability, in this case the name 'cache-control' and value 'no-cache, max-age=2419200, must-revalidate' are used.


Here, in the screenshot from Frontpage 2002, you can see exactly how a typical meta variable should be represented.

What this means...

cache-control   - This is the command that tells the server that you want to order the web server to cache pages in a specific manner.

no-cache  - this command tells the server not to automatically cache your web pages
max-age=2419200  - this tells the server the maximum time that a page may be cached may NOT exceed longer than 2419200 seconds (28 days)
must-revalidate - the server must revalidate whether the web page has been updated lately


Special note on 'max-age'

The maximum age can be set to ANY time you like, although it MUST be in the format of seconds. So, if you want your cached pages to be no older than 12 hours, the meta variable would be like this...

The main command strings remain just the same, except that the max-age has been changed to 43200 seconds. This means the cached page on a web server,  should NOT be more than 12 hours old

How long should you let your pages be cached ?

The answer to what maximum-age to set for a web page, should be dependent on a few issues.

- how often do you update the page ?
- is the page your index page, does it contain a lot of regularly updated content ?
- does the page contain a lot of content which rarely changes.


Some suggestions...

Home page : max-age=43200    (12 hours)

News pages, updated throughout the day : max-age=0   ( the page will NEVER cached by web servers)

Photo gallery pages, static content that rarely (if ever) changes :  max-age=2419200   (28days)

Net links

The following links will provide a wealth of info. about web-caching. Some is VERY in-depth and really too much for the average webmaster. However, some of the pages will confirm what I have discussed in this summary guide. : The best site on the net for a detailed account of how best to set your web pages for caching.

Some other useful sites...

Preventing web servers caching : A nice readable summary on web caching.

Summary on Use of Meta Tags  : A fair account of the basics of using the meta-tags to control the caching of web pages

Building Cache-friendly web sites : By, a quite technical account of web-caching.



Proceed to Pictorial guide on how to set your page properties for optimal Web caching

Last updated : 19/02/03