Friday, 15 March 2013

strange issue in iOS 6.0

Hi I found an article please read it,

We encountered a strange issue in iOS 6.0 during development. Please see the details below, existing apps which uses Ajax can break in iOS6.0

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

Device/OS : iOS 6.0

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 recommend method is adding a no-cache header.

This is how it is done.

jQuery

Check for iOS 6.0 and set Ajax header like this.

$.ajaxSetup({ cache: false });

ZeptoJS (iNav uses this library, so chances are many AMEX mobile websites uses this library)
Check for iOS 6.0 and set Ajax header like this.

$.ajax({
   type: ‘POST’,
   headers : { “cache-control”: “no-cache” },
   url : <your url>,
   data:<post data>,
   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.

.NET
Response.Cache.SetNoStore();

Or

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

PHP
header(‘Cache-Control: no-cache, no-store, must-revalidate’); // HTTP 1.1.
header(‘Pragma: no-cache’); // HTTP 1.0.


Hope these helps.

No comments:

Post a Comment