- This topic has 3 replies, 2 voices, and was last updated 6 years, 1 month ago by Anonymous.
-
AuthorPosts
-
-
February 27, 2018 at 10:59 am #65316AnonymousInactive
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.
-
February 27, 2018 at 2:29 pm #65330AnonymousInactive
Hi,
Thanks for the suggestion, I’ve updated our developer regarding, we’ll proceed accordingly.
Regards,
Lorenzo -
March 1, 2018 at 8:53 am #65555AnonymousInactive
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"); }
-
March 1, 2018 at 2:19 pm #65578AnonymousInactive
H @info1191,
Thanks for the updated, I’ll inform our team as well to verify anything yet. Thanks for the information though.
Regards,
Lorenzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.