Life's random bits By b1thunt3r (aka Ishan Jain)…
Internet Explorer AJAX cache bug

Internet Explorer AJAX cache bug

Ishan jain
We are on the edge of Internet Explorer 11, but there are still some organizations who still insists on using Internet Explorer 8. And it is us web developers who really suffers, because they don't upgrade to a newer browser.

As everyone might be aware IE8 is not a good platform for web development, in my opinion nothing can really beat Firebug when it comes to detective work (even chrome is 1000 times better then IE's development tools).
Today I was having some problems with a notifications system. The module worked like charm in Firefox and Chrome, but when it came to Internet Explorer (can't really say about any other version then 8), it was hell.

I was trying to read data via a jQuery.getJSON call from a ASP.net 4.0 WebForms application. But the darn browser would not return expected result. So, I started to fumble around with putting breakpoints, outputting values via console.log command, modified Server Side responses, and so on.

As I have been using primarily Firefox for development, and FireBug for debugging JavaScript, I thought I could just Write the object I was getting from the server to the console. But no, IE won't serialize the object for me (as FireBug does)!
Didn't really had time to create a function that could serialize the object for me, but luckily a quick search yielded a good result, by this time server should be returning a different object layout than the one I started with. Also I have was not seeing any new requests from IE in Fiddler.

From the serialized object and no results in Fiddler I could conclude that the IE was returning a cached version of the Data. Well, the solution was simple just add a time stamp to the URL, and now you will fool IE into skipping cache.

jQuery.getJSON('/ajax.ashx', {
  foo: 'bar',
  cacheId: new Date().getTime(),
}, function (data) {
  console.log(data);
});

In retrospect, I should have realized that IE have a cache in place for AJAX... But now I know to always throw a random number to bypass IE's super cache...