Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Chrome NOT to cache redirects?

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?

like image 646
thedk Avatar asked Nov 25 '12 17:11

thedk


People also ask

How can I make Chrome stop caching redirects?

#2: Clear Cache Data for a specific URLPress SHIFT+CTRL+I to open the Google Chrome Developer Tools panel. Go to the Network tab and select the Disable cache checkbox to enable that feature.

How do I remove cached redirects?

Open the Developer Tools Panel by pressing CTRL + Shift + i on Windows or Option + Shift + i on Mac. When you see a developer tools panel open, look the the left of your URL bar to see a refresh icon. Hold the refresh icon for a few seconds until a menu appears. Then click Empty Cache and Hard Reload .

Does not cache 301 redirect?

To prevent a 301 redirect from being cached just set the cache control headers, then you can undo the redirect and clients (bot and browsers) will no longer get redirected. A http status code 301 without caching can be used to do URL canonicalization while retaining the tracking functionality.

Why do I keep getting redirects on Chrome?

A Google Chrome redirect loop error occurs when the owner of a website changes their website URL (address) and the old one redirects you to the new one. Because this could be used maliciously, Google gives you an error when you try to reach the site.


1 Answers

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 )
like image 99
JxAxMxIxN Avatar answered Sep 28 '22 06:09

JxAxMxIxN