Solved

how to avoid cache wit meta tags?

Posted on 2011-02-24
4
552 Views
Last Modified: 2012-06-21
Dear Experts,
I use this code to prevent cache. I want my user to see the latest version of my web site.
I update my web site almost every week.
I'm not sure if the users who use proxy servers see my up-to-date page.
what should I do?
Is this below code enough?
<meta http-equiv="cache-control" content="no-cache" />

<meta http-equiv="pragma" content="no-cache" />

<meta http-equiv="expires" content="0" />
0
Comment
Question by:Braveheartli
  • 2
4 Comments
 
LVL 1

Author Comment

by:Braveheartli
ID: 34968796
My pages are mainly HTML
0
 
LVL 11

Assisted Solution

by:Murfur
Murfur earned 250 total points
ID: 34969480
Firstly, probably the only (and easiest) way to absolutely guarantee no caching is to change the filename slightly e.g. update-DATE-OF-UPDATE.html i.e. update-240211.html update-250211.html etc.
But this is probably impractical if you have a lot of links that refer to the original, so it really depends on how you have built your site!

META TAGS
META tags are processed in order, so for starters, put your cache related tags at the top of the list.
Also, note that some browsers will still cache a file that tells it not to (Big brother is watching...) but you can use the EXPIRES tag which forces the browser to get an up to date version at the next request for the page.

CACHE-CONTROL
Use of http-equiv="pragma" is effectively deprecated. It is the old HTTP 1.0 compliant method and unless your site visitor is using an obsolete browser like IE5 or Netscape 4 it is not used any more and can usually be ignored. The updated format is http-equiv="cache-control" but you can still use the pragma line to serve older browsers just in case one turns up. After all, in the post-apocalypse wasteland who knows what old computers might be re-activated...

ROBOTS
You may also want to consider blocking search engines from caching the page in their archives by making them ignore the page completely:
<meta name="robots" content="none">

But then you probably still want your site to be found with a search so you can allow indexing and linking (following links to your other pages) but deny archiving:
<meta name="robots" content="index, follow, noarchive">

EXPIRES
You may have seen this tag with a date and time specified. You can ignore the time as this is no longer read, particularly by search engines. But if you use a date then make sure it is in the correct format i.e. Thu, 24 Feb 2011
<meta name="expires" content="Thu, 24 Feb 2011" />

Alternatively, you can set your date to 0 which effectively sets the page as already expired (for those Big Brother browsers)
<meta name="expires" content="0" />

Also note that if you manage the date value properly you can reduce unnecessary workload for your server (remember that cached files will not be requested from the server) i.e. if you always update your page on a Sunday evening set the date at each update for the next weekend so that anyone coming to your site before the next update will have the advantage of cache. This is particularly good for you if you are paying for the bandwith used by your server as I am. I know it is only a few ยข per meg but it all adds up to several $ over time!
<meta name="expires" content="Sun, 27 Feb 2011" />


So, after all that your page might look something like this:


<html>
	<head>
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta name="expires" content="Sun, 27 Feb 2011" />
		<meta name="robots" content="index, follow, noarchive" />
		<title>Page title</title>
	</head>

Open in new window

0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 34969722
I use these two lines and it seems to work just fine.
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 01:00:00 GMT" />
<meta http-equiv="Pragma" content="no-cache">

Open in new window

0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 34991234
Thank u
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question