Home > Web Front-end > JS Tutorial > body text

Why Does Safari Cache POST Requests in iOS 6 Despite Cache Control Settings?

Susan Sarandon
Release: 2024-11-09 16:22:02
Original
750 people have browsed it

Why Does Safari Cache POST Requests in iOS 6 Despite Cache Control Settings?

Safari Cache Conundrum in iOS 6

Safari's introduction in iOS 6 has raised concerns regarding its cache handling for $.ajax calls. Specifically, POST requests made within a PhoneGap application are being cached despite explicitly setting the cache property to false.

The Root Cause

After thorough investigation, it was discovered that Safari selectively caches POSTs based on the following criteria:

  • The absence of Cache-Control headers
  • The presence of "Cache-Control: max-age=0" and an immediate "Expires" header

In accordance with the HTTP specification, POST responses are generally not cacheable. However, Safari on iOS 6 appears to be exploiting a provision that allows caching with appropriate Cache-Control or Expires headers.

The Workaround

To prevent Safari from caching POST requests, it is necessary to set "Cache-Control: no-cache" in the response headers. This ensures that Safari honors the cache bypass directive.

For a global solution that applies to all POSTs, add the following code to the server configuration:

<code class="apache">Header set Cache-Control "no-cache"</code>
Copy after login

If you only wish to disable caching for specific POSTs, you can use the following code:

<code class="apache">SetEnvIf Request_Method "POST" IS_POST
Header set Cache-Control "no-cache" env=IS_POST</code>
Copy after login

Note: Safari will still cache POST requests if the request parameters remain the same. To avoid caching, modify the request parameters on each call. Alternatively, you can append a random parameter to the request URL or POST data to ensure uniqueness.

The above is the detailed content of Why Does Safari Cache POST Requests in iOS 6 Despite Cache Control Settings?. 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