How do I get Chrome to NOT redirect caching?
Simple HTML:
<img src="http://someaddr/image.php"> image.php is a script that returns a random redirect to a static image with all the necessary no-cache headers:
Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache Expires: 0 Location: http://someaddr/random_image_12345.jpg Problem: When going back and forth to this HTML page, Chrome (latest version of win / mac) does not update the address http://someaddr/image.php .
I tried using 302 as well as 303 redirects (which in the RFC has a stronger requirement that it NEVER be cached by the browser). It works like a charm in IE, FireFox, Opera. They always update http://someaddr/image.php . But Chrome does not.
I even used developer tools in Chrome, and it seems that in Network Log it does not even show an attempt (cached or not) to select http://someaddr/image.php . The network log shows only one connection already http://someaddr/random_image_12345.jpg (cached). Why is it so broken ...
I know a naive / simple solution for placing a query string in an image source:
<img src="http://someaddr/image.php?refresh={any random number or timestamp}"> But I do not like / cannot use such hacks. Are there any other options?
Try redirecting 307
But if you are stuck trying to get to a link that won't work due to cached redirects ...
This does not clear the cache, but it is one quick and possible route around it if you are pulling your hair trying to get to a link that has been redirected to caching.
Copy the link address into the address bar and add some GET information to the address.
Example If Your Website 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 you already have one? in the url with some information 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 ) From the link posted in another question:
The first header Cache-Control: must-revalidate means that browser must send validation request every time even if there is already cache entry exists for this object. Browser receives the content and stores it in the cache along with the last modified value. Next time browser will send additional header: If-Modified-Since: 15 Sep 2008 17:43:00 GMT This header means that browser has cache entry that was last changed 17:43. Then server will compare the time with last modified time of actual content and if it was changed server will send the whole updated object along with new Last-Modified value. If there were no changes since the previous request then there will be short empty-body answer: HTTP/1.x 304 Not Modified You can use HTTP etags and recent modified dates to ensure that you are not sending browser data that it has already cached.
$last_modified_time = filemtime($file); $etag = md5_file($file); header("Last-Modified: ".gmdate("D, d MYH:i:s", $last_modified_time)." GMT"); header("Etag: $etag"); if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time || trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { header("HTTP/1.1 304 Not Modified"); exit; }