Safari Caching $.ajax Results on iOS 6: An Analysis
Since iOS 6's release, concerns have arisen regarding Safari's web view caching $.ajax calls. Despite explicitly setting the cache attribute to 'false,' unexpected caching behaviors persist, particularly for POST methods with static function signatures that consistently receive the same input parameters.
Root Cause
Investigation has revealed that Safari on iOS 6 caches POST requests that lack Cache-Control headers or contain "Cache-Control: max-age=0." This differs from other browsers that respect the non-cacheability of POST responses.
Workaround
To prevent caching globally, the only effective solution is to set "Cache-Control: no-cache." This header explicitly disallows caching.
Examples
Apache Configuration
To implement this workaround in Apache, add the following line to your config file:
Header set Cache-Control "no-cache"
Alternatively, to limit this behavior only to POST requests:
SetEnvIf Request_Method "POST" IS_POST Header set Cache-Control "no-cache" env=IS_POST
Additional Notes
It's worth noting that caching only occurs when the POST request parameters and URL remain unchanged. Introducing random data to the URL or POST payload can circumvent the caching issue.
The above is the detailed content of Why Does Safari on iOS 6 Cache $.ajax POST Requests Even with cache=false?. For more information, please follow other related articles on the PHP Chinese website!