google-chrome - 如何强制 Chrome 不缓存重定向?

标签 google-chrome caching redirect

一个简单的 HTML 代码:

<img src="http://someaddr/image.php">

image.php 是一个脚本,它返回一个随机重定向到带有所有必需的无缓存 header 的静态图像:
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Location: http://someaddr/random_image_12345.jpg

问题:在浏览此 HTML 页面时,Chrome(最新的 win/mac)不会重新验证地址 http://someaddr/image.php .

我曾尝试使用重定向 302 和 303(在 RFC 中有更强烈的要求,它不应被浏览器缓存)。这在 IE、FireFox、Opera 中就像一个魅力。他们总是刷新 http://someaddr/image.php .但 Chrome 没有。

我什至在 Chrome 中使用过开发者工具,似乎在网络日志中它甚至没有显示任何获取 http://someaddr/image.php 的尝试(是否缓存)。 .网络日志仅显示一个连接到 http://someaddr/random_image_12345.jpg (缓存)。怎么这么破……

我知道将查询字符串放入图像源的幼稚/简单解决方案:
    <img src="http://someaddr/image.php?refresh={any random number or timestamp}">

但我不喜欢/不能使用这样的黑客。还有其他选择吗?

最佳答案

尝试 307 重定向

但是,如果您在尝试访问由于缓存重定向而无法工作的链接时遇到困难...

这不会清除缓存,但如果您正在尝试访问已重定向缓存的链接,这是一种快速且可行的方法。

将链接地址复制到地址栏中,并在地址中添加一些GET信息。

示例
如果您的网站是 http://example.com

Put a ?x=y at the end of it 
( example.com?x=y ) - the x and y could be anything you want.

如果已经有 ?在 url 后面有一些信息
( example.com?this=that&true=t ) - try to add &x=y to the end of it...

( example.com?this=that&true=t&x=y )

关于google-chrome - 如何强制 Chrome 不缓存重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13553420/

相关文章:

caching - Blue Dragon Coldfusion 服务器缓存问题

javascript - 在background.html中监听NPAPI事件

java - 警告 : Unable to find an exact match for CDP version 107, 因此返回找到的最接近的版本:106

optimization - 将代码保存在 L1 缓存中

通过 Apache-Redirect 代理进行 Node.js Passport 身份验证

java - Struts2 重定向具有哈希值的 url

java - 从自己的java服务器重定向到tomcat

javascript - chrome onAuthRequired 不触发

css - 在网页上使用 Avant Garde BK BT 字体?

css - 如果父 css 文件使用查询字符串,@import css 文件是否仍会被缓存