Solved

how to avoid cache wit meta tags?

Posted on 2011-02-24
4
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I split a variable 19 45
Considerations PHP using multiple locations 9 34
PHP MYSQLI Connection in Function in a class 4 29
integrated two Separate file . 3 30
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

738 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