Monday, August 08, 2005

Form reset

FM was curious as to why a form would sometimes reset when you left a page and then used the "back" button to return to it. I've noticed this before and assumed it had something to do with cache control headers. I was right. I did a test using both server-generated headers and browser-simulated headers (meta http-equiv). The results:

Server-generated headers:
Two of the response headers had no effect on the form data: Expires and Pragma. The Cache-Control header, however, did have the effect being tested for when the value was no-store. Additionally, IE also shows this effect when the Cache-Control header has a value of no-cache, though no effect was seen in Firefox.

Browser-simulated headers:
The three meta http-equiv tags of interest (expires, pragma no-cache, cache-control no-cache) do not appear to cause the browser to reset a form on returning to a page using the browser history (back/forward). Note: I tried the full complement of options for cache-control with the same result.

Further testing would need to be done to see what the effect is on other browsers (Opera and Safari being of most interest).

During testing I also found that the browsers treat a hard reload ([Shift]+Reload) differently. IE will always completely reload a page and it's headers. Firefox, on the other hand, will reload the page but not update the headers until the browser is closed.