How to stop cache of web pages

Posted on 2005-04-24
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

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


    More info at :

    LVL 5

    Author Comment

    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.

    LVL 4

    Expert Comment

    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

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
    Read about why website design really matters in today's demanding market.
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    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.

    734 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

    17 Experts available now in Live!

    Get 1:1 Help Now