Learn how to a build a cloud-first strategyRegister Now


How to stop cache of web pages

Posted on 2005-04-24
Medium Priority
Last Modified: 2010-08-05
I had problems with a Flash application that was communicating with a sever App. that I wrote in Perl.

PC a) worked OK, the flash app (a game) always received info from the server app.

PC b) went into a loop, always seeming to get the same info from the server.

Eventually I realised that PC a) had IE set to check for newer versions of a page every time, PC b) was set to check automatically. When I changed PC b) to check every page the flash app. worked.

I cannot ensure that everyone using my Flash program will have this setting, how do I change (presumably my server app.) to make sure the page data is never cached?

The server app communicates via http, data from the Flash app is sent as 'get' parameters. Data is sent back from the server as a text/html page.


Question by:icd
LVL 32

Expert Comment

ID: 13855136
You can try to use <meta> tags on your HTML page to disallow cache


More info at : http://www.i18nguy.com/markup/metatags.html


Author Comment

ID: 13855240
My understanding is that the META tags may be understood by the browser, but not necessarily by any proxy servers?

I have tried using 'Cache-Control: no-cache\n' in the headers. I think this (or something like it) may be the final solution.


Expert Comment

ID: 13855276
To tell a proxy not to cache a webpage use the Cache-Control HTTP header and set it to 'private'.
If it is set to 'no-cache', then the proxy and the user's browser will not cache the page.

Because the HTTP/1.0 specifications do not recognize the Cache-Control HTTP header, it is good to also use the Pragma HTTP header to specify that a webpage shouldn't be cached. Below you can find out how to send the HTTP headers either in PHP and ASP, but the code must appear before sending the html portion of a webpage.

---- PHP --------------
       header("Cache-Control: private");
       header("Pragma: no-cache");

---- ASP --------------
       Response.AddHeader "Cache-Control", "private"
       Response.AddHeader "Pragma", "no-cache"

---- MetaTAG --------------
    <meta http-equiv="Cache-Control" content="private">
    <meta http-equiv="Pragma" content="no-cache">
LVL 29

Accepted Solution

rdivilbiss earned 500 total points
ID: 13855293
If it were a perfect world all the browsers would obey the cache control commands and this would be easy.  Unfortunately, the developers of web browsers have consistantly decided to do their own thing regards to caching.

To make matters worse, Internet Explorer has a cache bug...

Here are some meta tags you should consider using.  Some work on some browsers, and some work on others.  Unfortunately nothing works right on ALL browsers.

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="cache-control" content="private">
<meta http-equiv="cache-control" content="max-age=0, must-revalidate">
<meta http-equiv="expires" content="now-1">
<meta http-equiv="pragma" content="no-cache">

LVL 29

Expert Comment

ID: 13855312
If you have ASP these might (or might not) help.

<% ' no browser caching of this page !! to be used on all pages %>
<% Response.Expires=-1 %>
<% Response.ExpiresAbsolute = Now() - 1 %>

<% ' do not allow proxy servers to cache this page !! to be used on all pages%>
<% Response.CacheControl="private" %>
<% Response.CacheControl="no-cache" %>
<% Response.CacheControl="no-store" %>

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 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