Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Why does back-buttoning to a cgi script-output page yield 'Page expired'?

by Russ (Deacon)
on Jan 11, 2007 at 23:25 UTC ( [id://594265] : note . print w/replies, xml ) Need Help??

in reply to Why does back-buttoning to a cgi script-output page yield 'Page expired'?

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.