【问题标题】:how to force all browsers to not store your site's cache?如何强制所有浏览器不存储您网站的缓存?
【发布时间】:2014-01-28 00:06:21
【问题描述】:

当您处于开发阶段时,不断提醒您的客户清除缓存或要求他们“刷新页面一堆”有点尴尬。

有没有我开发者可以在 nginx 中设置或作为 HTML 中的元标记来强制所有浏览器停止缓存我的页面的设置?

【问题讨论】:

标签: html caching nginx page-caching


【解决方案1】:

尝试设置这些标题:

"Cache-control: no-store, no-cache, must-revalidate"
"Expires: Mon, 26 Jun 1997 05:00:00 GMT"
"Pragma: no-cache"
"Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"

这将阻止浏览器兑现页面。

【讨论】:

    【解决方案2】:

    理论上,根据Difference between Pragma and Cache-control headers?http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32,在nginx中,以下可能就足够了:

    add_header  Cache-Control   no-cache;
    

    在实践中,您可能需要指定一些额外的指令;似乎使用 expires 指令就足够了,它也会自动添加上面的 Cache-Control 标头:

    expires -1;
    

    【讨论】:

    • @Ramin,当然;甚至可以在location 中的if 中使用它。
    猜你喜欢
    • 2018-06-22
    • 2016-10-01
    • 2010-09-12
    • 2011-10-08
    • 2010-11-20
    • 2023-03-11
    • 2011-10-11
    相关资源
    最近更新 更多