Home > Web Front-end > JS Tutorial > Why Does iOS 6 Safari Cache My $.ajax Calls Even With `no-cache` Headers?

Why Does iOS 6 Safari Cache My $.ajax Calls Even With `no-cache` Headers?

Susan Sarandon
Release: 2024-11-05 04:18:02
Original
618 people have browsed it

Why Does iOS 6 Safari Cache My $.ajax Calls Even With `no-cache` Headers?

iOS 6 Safari: Caching $.ajax Calls

Safari's web view in iOS 6 has been observed to cache $.ajax calls, even when explicitly specified not to. This peculiar behavior has been encountered in the context of PhoneGap applications, which utilize the Safari WebView.

Cause of Caching Issue

Investigation has revealed that Safari caches POST requests that lack Cache-Control headers or contain the header "Cache-Control: max-age=0." This behavior stems from an interpretation of the HTTP spec, which states that POST responses can be cached with appropriate headers.

Solutions

To prevent caching, the Cache-Control header should be set to "no-cache." This can be achieved globally in Apache configurations using:

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

For POST requests specifically, the same setting can be applied using:

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

Alternatively, a workaround is to modify function signatures:

getNewRecordID(intRecordType, strTimestamp)
Copy after login

By adding a timestamp parameter to the function signature, the request effectively changes with each call, preventing caching.

The above is the detailed content of Why Does iOS 6 Safari Cache My $.ajax Calls Even With `no-cache` Headers?. 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