如何强制Chrome不缓存重定向? [英] How to force Chrome NOT to cache redirects?
问题描述
简单的HTML代码:
< img src =http://someaddr/image.php>
image.php是一个脚本,它将随机重定向返回到一个静态图像,并带有所有必要的no-cache头文件:
$ p $ Cache-Control:no-cache,no-store,must-revalidate
Pragma:no-cache
过期:0
地点: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 = {任意随机数或时间戳}>
但我不喜欢/不能使用这样的黑客。有没有其他选择?
尝试307重定向
但如果您因为缓存重定向而无法连接到某个链接...
这并不能清除缓存,但如果你想要找到一个已被重定向缓存的链接,那么这是一条快速且可行的路线。
将链接地址复制到地址栏中,并在地址中添加一些GET信息。
示例您的网站 http://example.com
在其末尾放置一个?x = y
(example.com?x = y) - x和y可以是任何你想要的。
如果已经有了?在它后面的一些信息的url
(example.com?this=that&true = t) - 尝试添加& ; x = y到它的结尾...
(example.com?this=that&true=t&x=y)
A simple HTML code:
<img src="http://someaddr/image.php">
image.php is a script that returns a random Redirect to a static image with all necessary no-cache headers:
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Location: http://someaddr/random_image_12345.jpg
The problem: when navigating back and forward to this HTML page, Chrome (latest win/mac) does not revalidate address http://someaddr/image.php
.
I have tried using redirects 302 and also 303 (which in RFC has stronger requirement that it should NEVER been cached by browser). This works like a charm in IE, FireFox, Opera. They always refresh http://someaddr/image.php
. But Chrome doesn't.
I have even used Developer Tools in Chrome, and it seems that in Network Log it even don't shows any attempt (cached or not) of fetching http://someaddr/image.php
. Network Log shows only one connection already to http://someaddr/random_image_12345.jpg
(cached). Why this is so broken...
I know the naive/simple solution of putting query string in image source:
<img src="http://someaddr/image.php?refresh={any random number or timestamp}">
But I don't like/can't use hacks like that. Are there ANY other options?
Try a 307 redirect
But if you're stuck trying to get to a link that won't work due to a cached redirect...
This doesn't clear the cache but it's one quick and possible route around it if you're pulling your hair out trying to get to a link that has been redirect cached.
Copy the link address into the address bar and add some GET information to the address.
EXAMPLE If your site is 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.
If there is already a ? in the url with some info after it
( example.com?this=that&true=t ) - try to add &x=y to the end of it...
( example.com?this=that&true=t&x=y )
这篇关于如何强制Chrome不缓存重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!