Solved

how to avoid cache wit meta tags?

Posted on 2011-02-24
4
531 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 85
PHP_POST() error message 9 41
hiding/removing php extension - best practice 4 24
CDO.Message not able to send attachement 5 12
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now