i am trying to serve cacheable Content depending on whether it is an ajax request or not.
Scenario:
A little PHP-script "/test.php" serves some HTML-Output and sets the following Headers:
Expires Wed, 23 Feb 2011 13:30:06 GMT
Cache-Control public, max-age=60
Vary X-Requested-With,Accept-Encoding
The Output depends on the $_SERVER['HTTP_X_REQUESTED_WITH']
state.
When my Firefox points to the Url i get the output, and for the next Minute i get the same result from the Browser-Cache, not hitting the server. OK, so far.
When I request the same resource via a XMLHttpRequest
(with X-Requested-With: XMLHttpRequest
Header), my Firefox does NOT request the Server, but serves the (wrong) response from Cache!
For the other way round, its the same. An Ajax-Call on the resource fills the cache, and a subsequent Browser-Request serves the (wrong) response from Cache.
Does anyone have experience with this topic? I think this should be a common enough issue - serving content depending on whether its ajax or not (on the same URL).
greetings, Ilja