Home > Web Front-end > JS Tutorial > Why Does Safari on iOS 6 Cache $.ajax POST Requests Even with cache=false?

Why Does Safari on iOS 6 Cache $.ajax POST Requests Even with cache=false?

Linda Hamilton
Release: 2024-11-03 22:50:03
Original
1052 people have browsed it

Why Does Safari on iOS 6 Cache $.ajax POST Requests Even with cache=false?

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

  • No Cache-Control or Expires headers: Caching will occur.
  • Cache-Control max-age=0 and an immediate Expires: Caching will occur.
  • Cache-Control: no-cache: Caching will NOT occur.

Apache Configuration

To implement this workaround in Apache, add the following line to your config file:

Header set Cache-Control "no-cache"
Copy after login

Alternatively, to limit this behavior only to POST requests:

SetEnvIf Request_Method "POST" IS_POST
Header set Cache-Control "no-cache" env=IS_POST
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template