Solving AJAX caching in Internet Explorer (IE) using Cake PHP

With my latest project, Passbook, there are a lot of AJAX events and a lot of GUI behaviour that is enabled using jQuery. While using a good library keeps most things cross-browser compatible there are still a few IE specific issues that can only be addressed through special commands. One of those issues is IE's overzealous caching of page content.

Common behaviour of IE AJAX calls are a lack of change between calls. So if you are loading a value it stays the same no matter what if only the POST variable changes. This makes it pretty much unusable as well as extremely difficult to debug as it becomes impossible to observe the imapct of code changes. The solution is quite simple and only involves one line of code: $this->disableCache()

Calling disableCache() in the controller before the view is rendered will cause Cake to output header values that tells the browser to not cache the results. Doing so explicitly is a necessity for IE when dealing with functions that primarily return results to AJAX calls. You can also use it for dynamic content that should not be cached as well.


Unknown said...

Good call. I had conveniently forgotten of this method and did a quick Google search for IE ajax caching in Cake.

Thank ya.

Unknown said...

Thank you oh so very much! :))
it solved my problem in an instant!

Post a Comment