HTTP response caching

后端 未结 3 1952
故里飘歌
故里飘歌 2020-12-02 23:29

I want to ensure that my servet\'s response is never cached by the broswer, such that even if two identical requests are made (a nanosecond apart), the server is always cont

相关标签:
3条回答
  • 2020-12-03 00:01

    According to microsoft, these headers are required for IE:

    • Cache-Control;
    • Pragma;
    • Expires (that should be negative);

    Example:

    Pragma: no-cache
    Cache-Control: no-cache
    Expires: -1
    
    0 讨论(0)
  • 2020-12-03 00:02

    We use:

        // HTTP 1.1
        response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
        // HTTP 1.0
        response.setHeader("Pragma", "no-cache");
    
    0 讨论(0)
  • 2020-12-03 00:07

    No, that's not the correct way. Here is the correct way:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    

    You'll probably see someone else suggesting other entries/attributes, but those are completely irrelevant when at least the above are mentioned.

    Don't forget to clear your browser cache before testing after the change.

    See also:

    • Caching tutorial for webmasters
    • Making sure a page is not cached across all browsers
    0 讨论(0)
提交回复
热议问题