What's the code to disallow an HTML page from being cached?
| SitePoint Sponsor |

What's the code to disallow an HTML page from being cached?
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
Source
You should also use the HTTP 1.1 cache-control: no-cache, e.g.
Bear in mind that not all browsers will honour meta http-equiv directives. So, ideally, you should use the HTTP cache-control and pragma directives directly at the HTTP level. Most server-side processing systems (JSP, ASP, etc.) should let you get at these.Code:<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
See http://www.w3.org/Protocols/rfc2616/...4.html#sec14.9 and http://www.w3.org/Protocols/rfc2616/....html#sec14.32 for details.
There's a whole raft of other caveats, too.
Remember that using these directives can break the user's back button, which WILL cause severe usability problems.
Preventing all caching in a long sequence of forms (e.g. an e-commerce system) will probably cost you a very large number of broken sessions, as users find out the hard way about the back button being broken. This is a really good way to annoy users and lose business. As such, you should only do this if you have a REALLY good reason to do so. "My session handler can't cope with users using their back button" is NOT a good enough reason, IMO.
The usability implications are the main reason for the existence of the more flexible Cache-Control directives in HTTP 1.1. Unfortunately, support for HTTP 1.1 is lacking in many older browsers.
gav
http://www.livejournal.com/users/blufive/
browser stats analysis and comment:
http://www.livejournal.com/community/stats_weenie/
I think the purpose would be to have these non cached pages within a frames page... whereby the only page that would be cached is the main frame and/or home page...
As blufive says, that's not the right way to do it, nor does it necessarily work.Originally posted by Husain
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
Source
You have to modify the HTTP response.
Add the following lines to the HTTP response header:
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate
The pragma: line is for compatibility with older http 1.0 browsers and proxies.
If you don't know how to add lines to the HTTP response header, then you really need to learn a bit more about http. You can do it with server-side scripts. Alternatively, you can also do it in apache if you have the right modules installed ie. mod_expires
[mmj] My magic jigsaw
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Bit Depth Blog · Twitter · Contact me
Neon Javascript Framework Jokes
Bookmarks