Solved

how to avoid cache wit meta tags?

Posted on 2011-02-24
4
517 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
Comment Utility
My pages are mainly HTML
0
 
LVL 11

Assisted Solution

by:Murfur
Murfur earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank u
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

763 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

13 Experts available now in Live!

Get 1:1 Help Now