Coldfusion: IE Cache problem with repeating Ajax Requests

05/25/2010
0

If you use Coldfusion to create Javascript endpoints - e.g. for Ajax Requests, then everything might work just fine at first sight.

Later some users might report that in Internet Explorer (6.0, 7.0 and 8.0) content that you refresh via Ajax requests might not get updated.

Here’s why:

Suppose you have a HTML page that contains an Ajax Request to a .cfm file to get the content of the users inbox. The .cfm file returns a JSON string with all items in the inbox. This request might look something like this:

http://yourdomain.com/ajax/json.cfm?do=inbox

The json.cfm will return all items for this users inbox (depending on the Session.UserID of course).

When you first load the page everything works fine. You load the page, the page requests http://yourdomain.com/ajax/json.cfm?do=inbox and renders the inbox with its items.

BUT: When the user now returns to this page within the same browser session the Ajax request will be answered from IEs cache.

Turns out your need to set the correct HTTP headers to really prevent IE from caching your Ajax requests:

<cfheader name="Cache-Control" value="no-cache">
<cfheader name="Expires" value="0">

The bad thing about this behavior in IE is, that it is not really creating an error or anything it is simply using old or stale data when it shouldn’t. While you test your application you will only realize this if you extensively test your application in IE against this.

For my part i work with Firefox, Safari or Chrome and test most apps there. I check if everything works fine from time to time in IE but this issue is something that will clearly not be noticed at first sight. Hope the above helps you.

If you've read this far you might as well follow me on Twitter here.


Comments