PermaLinkKeep AJAX-returned XML from storing in user's browser cache
posted Wednesday 21st, February 2007
 



Yesterday I posted about adding the current date/time as a dummy parameter to the end of a url in an AJAX request ...to ensure that the request would fetch a fresh set of data. Julien Bottemanne was kind enough to post a comment about some optimization that one may want to do to help keep the caches of users' browsers from getting populated with the XML streams from these requests. Doing a little searching on the IBM site, I found some references to explain Julien's brilliant suggestion.

IBM has documented this type of use of a Web Site Rule (the HTTP response header type) to prevent caching. Here are the suggestions from Julien's comment and from the IBM posting:
  • Create a Web Site Rules document
  • Provide a meaningful Description, like 'Prevent caching on ReadViewEntries'
  • Set the 'Type of rule' to be 'HTTP response headers'
  • Set the 'Incoming URL pattern' to whatever makes sense. So in this case it might make sense to establish a standard for your shop to use when sending ajax requests to the server. Perhaps agree that all ajax calls should be done against views that have been created for this purpose, so that the view alias name begins with the characters 'vwAjax'. Then specify an Incoming URL pattern of '*.nsf/vwAjax*'
  • Set 'HTTP resonse codes' to '200, 206'. 200 is the standard success code. 206 indicates that a partial GET request has been successful (see RFC 2616)
  • Set 'Expires header' to 'Always add header', and 'Specify as date', specifying a date far in the past (01/01/1990 is recommended in the IBM documentation)
  • The IBM recommendation for 'Custom headers' is to populate as follows:
    • Name: Cache-Control Value: no-cache Override: Yes
    • Name: Pragma Value: no-cache Override: Yes
    • Name: Last-Modifed Value: Fri, 01 Jan 1990 00:00:01 GMT Override: Yes
Here's a screen shot (with minor modification) of a table from the IBM documentation, showing the suggested values for the Web Site Rule document:
ajax Web Site Rule

Thanks Julien!
Comments :
 
 
No comments.