Any AJAX developer will tell you that it’s just common sense to use POST over GET when submitting requests where the response should not be cached.

However – as I just learned today – that sense is not so common after all.

I’ve been trying to get a Cordova app which uses heavy AJAX to function on iOS on-and-off for the last couple of months. I could never understand why the iOS version wouldn’t work but any desktop browser (including Safari) and the Android version would. Plugging the desktop safari debugger into the iOS simulator showed that my polls were going through but – apparently – no data was being returned from the server in the response bodies.

The fact is, contrary to every other browser, mobile Safari (and therefore Cordova) caches POST responses by default. Those polls that looked like they were reaching my server were actually striking the cache. Talk about confusing.

Finding the problem was the hard part. Fortunately, fixing it is easy as pie. Simply add

Pragma: no-cache

to your response headers.

Be Sociable, Share!
  • Twitter
  • Facebook
  • email
  • StumbleUpon
  • Delicious
  • Google Reader
  • LinkedIn
  • Digg
  • Google Bookmarks
  • Reddit
  • Tumblr