SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page that doesn't cache: what's the code

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

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">

    Source

  3. #3
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should also use the HTTP 1.1 cache-control: no-cache, e.g.
    Code:
     <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    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.

    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.

  4. #4
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  5. #5
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Husain
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">

    Source
    As blufive says, that's not the right way to do it, nor does it necessarily work.

    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 Android stuff


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •