iOS 6.0 caching Ajax POST requests

Problem : Ajax requests are triggered from browser but not hitting the server. The requests are cached.

Device/OS : iOS 6.0 Safari

Platform (confirmed but not limited to) : Mobile web , Phone gap

Reason: By design iOS 6.0 is caching Ajax requests. This mostly happens when POST data is same as that of previous Ajax request. In iOS 6.0 POST requests are cached in the absence of no-cache headers.

This is considered as a bug because in other mobile/desktop browsers and iOS previous versions the POST requests are not cached even if no-cache headers are not set. Also this issue in iOS 6.0 causes existing web apps to break.

The issue has been fixed in iOS 6.1 beta release.

How to fix it: There are various methods to prevent caching of requests. The recommended method is adding a no-cache header.

This is how it is done.


Check for iOS 6.0 and set Ajax header like this.

$.ajaxSetup({ cache: false });

ZeptoJS :

Check for iOS 6.0 and set Ajax header like this.

type: 'POST',
headers : { "cache-control": "no-cache" },
url : ,
dataType : 'json',
success : function(responseText) {…}

Server side

Java :

httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");

Make sure to add this at the top the page before any data is sent to the client.






header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
This entry was posted in Mobile Web, Web development and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>