Viewing 3 reply threads
  • Author
    Posts
    • #65316
      Anonymous
      Inactive

      We found that Chrome was caching a number of requests as these were being redirected with a 302 status code without headers to prevent caching. Specifically this occurred from the ‘Edit Order’ screen when creating a shipment in Australia Post – the page would often reload without creating the shipment.

      The below code fixes this issue:

      //Prevent caching of API requests to Australia Post
      $is_api_call = false;
      if( !empty($_GET) ){
      	foreach($_GET as $get => $gval){
      		if( false !== strstr($get, 'wf_australiapost_') ){
      			$is_api_call = true;
      		}
      	}
      }
      if( $is_api_call ){
      	header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
      	header("Cache-Control: post-check=0, pre-check=0", false);
      	header("Pragma: no-cache");
      }
      add_filter( 'wp_redirect_status', 'rfg_change_redirect_status' );
      function rfg_change_redirect_status( $status=302 ){
      	if( 302 == $status ){
      		$status = 307;
      	}
      	
      	return $status;
      }

      This adds PHP headers to prevent caching of these pages where a $_GET variable starts with ‘wf_australiapost_’. It also changes the 302 redirects to 307 redirects which browsers are less likely to cache.

    • #65330
      Anonymous
      Inactive

      Hi,

      Thanks for the suggestion, I’ve updated our developer regarding, we’ll proceed accordingly.

      Regards,
      Lorenzo

    • #65555
      Anonymous
      Inactive

      Upon further testing, the bottom section of the above code (replacing 302 redirects with 307 redirects) was not needed and has some detrimental side-effects.

      For anybody looking to fix these issues, use the below:

      //Prevent caching of API requests to Australia Post
      $is_api_call = false;
      if( !empty($_GET) ){
      	foreach($_GET as $get => $gval){
      		if( false !== strstr($get, 'wf_australiapost_') ){
      			$is_api_call = true;
      		}
      	}
      }
      if( $is_api_call ){
      	header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
      	header("Cache-Control: post-check=0, pre-check=0", false);
      	header("Pragma: no-cache");
      }
    • #65578
      Anonymous
      Inactive

      H @info1191,

      Thanks for the updated, I’ll inform our team as well to verify anything yet. Thanks for the information though.

      Regards,
      Lorenzo

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Scroll to Top