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

编程入门 行业动态 更新时间:2024-10-25 04:14:14
本文介绍了如何强制Chrome不缓存重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

简单的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信息。

示例您的网站 example

在其末尾放置一个?x = y (example?x = y) - x和y可以是任何你想要的。

如果已经有了?在它后面的一些信息的url

(example?this=that&true = t) - 尝试添加& ; x = y到它的结尾... (example?this=that&true=t&x=y)

A simple HTML code:

<img src="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: someaddr/random_image_12345.jpg

The problem: when navigating back and forward to this HTML page, Chrome (latest win/mac) does not revalidate address 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 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 someaddr/image.php. Network Log shows only one connection already to 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="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 example

Put a ?x=y at the end of it ( example?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?this=that&true=t ) - try to add &x=y to the end of it... ( example?this=that&true=t&x=y )

更多推荐

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

本文发布于:2023-10-31 19:10:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   重定向   Chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!