This is really a feature, though many users find it an annoyance. In the HTTP standard, the intent is to limit network traffic transferring files that have not changed. So, if your browser has already received a file, it will not fetch it over and over again (unless you have set it do so).

Dynamically created content — like the output of cgi scripts — needs an expiration to let your browser know how long it will be valid. Imagine you are coding a web app that shows the results of a monitoring process that updates every five minutes. If you know your results will be the same until the next "refresh" in three minutes, you can tell browsers the data will expire in three minutes and prevent them from executing your computationally expensive code until you have something new to report.

If you don't tell the browser how long the data will be valid, it won't know when to refresh from the server and when to display its cached data.

Users commonly expect the Back button to merely return to what was last shown, but this is an example of a user interface not doing what is expected. Refusing to show anything because the old result has expired seems invasive when the cache still holds the last page viewed, but that is a common (standard?) browser behavior.

So, to let the browser keep its results and show them to the user as often as s/he wants, set the expires time in the HTTP header.

# Cache these results for one hour print $cgi->header(expires => '+1h');
There are several cache control headers. See cianoz's answer for examples; see The W3C standard for more information.


In reply to Re: Why does back-buttoning to a cgi script-output page yield 'Page expired'? by Russ
in thread Why does back-buttoning to a cgi script-output page yield 'Page expired'? by dyfn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.