How to force Chrome NOT to cache redirects?

前端 未结 2 770
刺人心
刺人心 2020-12-18 03:23

A simple HTML code:


image.php is a script that returns a random Redirect to a static image wi

相关标签:
2条回答
  • 2020-12-18 03:35

    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 )
    
    0 讨论(0)
  • 2020-12-18 03:41

    From a 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's etags and last modified dates to ensure that you're not sending the browser data it already has cached.

    $last_modified_time = filemtime($file); 
    $etag = md5_file($file); 
    
    header("Last-Modified: ".gmdate("D, d M Y H: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; 
    } 
    
    0 讨论(0)
提交回复
热议问题