Link to home
Start Free TrialLog in
Avatar of icd
icd

asked on

How to stop cache of web pages

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.

Regards
ICD

Avatar of Batalf
Batalf
Flag of United States of America image

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

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

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

Batalf
Avatar of icd
icd

ASKER

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.

Regards
ICD
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 --------------
    <?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">
ASKER CERTIFIED SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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" %>