Friday, January 25, 2008

Browser Caching in Internet Explorer Is Preventing Real-Time Data

AJAX Problem with IE6

When your web page uses Javascript to update the content of a markup
element, Internet Explorer looks at the web address of that remote
procedure call very closely. If the address exactly matches an address
that has been previously "RPCed", it will return the cached copy of
that request from the browser (rather than downloading a fresh copy
from the web server).

Did you know that you that you can use multiple URLs to get to the
exact same web resource? The following URLs, although different, go to
the exact same web page:

* http://www.lonniebest.com/Music/?key=PleaseTakeMeElsewhereThisGuyIsCrazy
* http://www.lonniebest.com/Music/?key=WhoIsThisNut

By changing the query string portion of the URL, we change the URL,
but we don't necessary change the web resource that handles the
request. Internet Explorer won't return a cached version of a page if
the entire URL is technically different. So you can prevent IE from
caching by ensuring that each remote procedure call has a URL that has
not been previously requested. Specifically, by adding an
unprecedented key/value pair to the query string portion of the URL,
IE will request fresh data from your web server (and your web server
will simply ignore the unprecedented key/value pair). So how do you
ensure the URL is unprecedented? Use javascript's time functions to
add an unprecedented key/value pair to the query string's key/value
collection.