Disable browser caching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Mueller

    Disable browser caching

    Today I'm using
    <html>
    <head>
    <meta http-equiv = "pragma" content = "no-cache">
    </head>


    This prevent the browser to cache the page. So each time I call the
    following PHP script
    <?php
    echo date("d.m.Y") . " / " . date("H:i:s") . "<br>";
    ?>
    the current time will be displayed.

    However, if I call this PHP script over a proxy the time gets not updated.
    I always have to press Shift + Reload.

    A colleague told me that I have to program the no-caching-command somehow
    within the http header.
    How to do that and does this really solve my problem?

    Stefan


  • Ewoud Dronkert

    #2
    Re: Disable browser caching

    Stefan Mueller wrote:[color=blue]
    > <meta http-equiv = "pragma" content = "no-cache">[/color]

    For starters, add cache-control and no-store. See
    Useful HTML Meta Tags are listed and described, and example usages are given. Links to other resources are also provided.

    Firefox 1.5 uses in-memory caching for entire Web pages, including their JavaScript states, for a single browser session. Going backward and forward between visited pages requires no page loading and the JavaScript states are preserved. This feature, referred to by some as bfcache (for "Back-Forward Cache"), makes page navigation very fast. This caching state is preserved until the user closes the browser.


    Using http://php.net/header you can send headers more reliably than
    through the meta tag (especially when dealing with proxies).

    --
    E. Dronkert

    Comment

    • Darkstar 3D

      #3
      Re: Disable browser caching

      <?php
      // Date in the past
      header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");

      // always modified
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

      // HTTP/1.1
      header("Cache-Control: no-store, no-cache, must-revalidate");
      header("Cache-Control: post-check=0, pre-check=0", false);

      // HTTP/1.0
      header("Pragma: no-cache");
      ?>

      Comment

      • Alvaro G. Vicario

        #4
        Re: Disable browser caching

        *** Stefan Mueller escribió/wrote (Sat, 10 Dec 2005 20:22:50 +0100):[color=blue]
        > A colleague told me that I have to program the no-caching-command somehow
        > within the http header.[/color]

        That's correct. As far as I know, proxies do not parse or even read the
        HTML they serve. So HTML is not a good place to give directions :)


        --
        -+ Álvaro G. Vicario - Burgos, Spain
        ++ http://bits.demogracia.com es mi sitio para programadores web
        +- http://www.demogracia.com es mi web de humor libre de cloro
        --

        Comment

        • Michael Winter

          #5
          Re: Disable browser caching

          On 10/12/2005 20:15, Ewoud Dronkert wrote:

          [snip]
          [color=blue]
          > See
          > http://www.i18nguy.com/markup/metatags.html[/color]

          It should probably be expressed, more strongly than it has been, that
          cache- (Expires, Cache-Control, etc.) and content-related (Content-Type,
          Content-Language, etc.) directives should only be send via HTTP headers.
          Clients will want to know this information /before/ they start parsing
          the entity body, and others won't even look there.

          Trying to substitute HTTP headers (any really, but these especially) for
          META elements is very questionable.

          [snip]

          Mike

          --
          Michael Winter
          Prefix subject with [News] before replying by e-mail.

          Comment

          • Stefan Mueller

            #6
            Re: Disable browser caching

            I'm using
            <?PHP
            Header('Cache-Control: no-cache');
            Header('Pragma: no-cache');

            and that works great.

            Many thanks
            Stefan


            Comment

            Working...