Sunday, September 11, 2011

IE caching issue (XML)

Have you ever wonder why your internet explorer browser is not showing the updated data on a webpage where the data is fetched from the server as an xml file?

You checked with other browsers like Firefox and chrome, things are absolutely fine, but when it comes to internet explorer, the data is same old as before even if you hit refresh.

Well. I experienced the same problem with 2 projects. I figure out 2 solutions.

Solution 1 -
Change the temporary internet files setting as shown in the picture below.
As shown above, you can change caching option to every time I visit the webpage which is automatically by default. You can reach to this dialog box by Internet Options -> Browser history (Setting clicked).

However this solution will work only on that particular browser where the setting is done.
This is not desirable solution on public sites.

Solution 2 -
Here you don't have to change the client side settings. Changes has to be done in the server side by 2 ways.
       1. By adding a caching header to the xml request such as cache-control to no-cache.
       2.By appending a random  query parameter to the GET http request (e.g, www.xyz.com/sample.xml?      randomVar=[random number], the random number could be generated from javascript code using math.random() function and then appended to the get request ).

Both of them works.

Happy programming
Bijay




No comments:

Post a Comment