Caching Conundrum: Safari's Selective Fetching in iOS 6
Since iOS 6's release, developers have encountered an unexpected behavior in Safari's web view: $.ajax POST calls are being obstinately cached despite cache:false settings. Intriguingly, this anomaly only manifests when the called function employs a static signature.
Preliminary investigations revealed that Safari caches POST responses only if they lack Cache-Control or Expires headers or if Cache-Control is set to max-age=0. However, granting the request "Cache-Control: no-cache" bypasses this behavior, preventing caching altogether.
Apple's decision to leverage this HTTP specification provision for POST methods (section 9.5) has left developers bewildered. While caching POST responses is not unheard of, Safari's choice to do so without any headers or with max-age=0 seems to be a deviation from conventional browser behavior.
To resolve this caching quandary, a global solution within an Apache configuration is as follows:
Header set Cache-Control "no-cache"
However, if selectively applying the "no-cache" directive to only POST requests is preferred, Apache offers a solution:
SetEnvIf Request_Method "POST" IS_POST Header set Cache-Control "no-cache" env=IS_POST
Alternatively, adding a unique parameter to the URL or POST data can circumvent the caching issue for static function signatures.
The above is the detailed content of Why Does Safari Cache POST Requests in iOS 6 Despite \'cache:false\'?. For more information, please follow other related articles on the PHP Chinese website!