I'm having a peculiar problem:
PHP SCRIPT:
// checks If-Modified-Since header (if nothing has changed)
// Sends HTTP/1.0 304 Not Modified
// Sends Cache-control: public, must-revalidate
// exits
// if NO If-Modified-Since or something has changed
// builds content
// Sends Last-Modified: [DATE TIME]
// Sends Cache-control: public, must-revalidate
// exits
I am using jQuery AJAX to attempt to refresh the content on demand, I am trying to do this by altering the If-Modified-Since header with a DATE TIME in the past, using the "beforeSend" param.
This is currently what happens:
- Request is made, 200 OK response with fresh content
- Subsequent requests get a 304 response and browser pulls from cache
- CONTENT IS CHANGED on the server
- A request is made with modified If-Modified-Since header (no URL string altering), 200 OK response with fresh content
- Subsequent requests (without altering If-Modified-Since header) seems to retrieve old content from step #1
I guess im under the impression that at step #4, the browsers content should have been refreshed, what am i missing?
I setup a little test so you can try and see what i mean: http://tweetplenty.com/test/test2.php ... use FF and firebug if you can as im using console.log() ... here is the order of operations:
the "normal" link will do a request to http://tweetplenty.com/test/test.php without modifying if-modified-since ... subsequent requests using the "normal" link should return a 304 (it should return 200 OK every 60 seconds)
the "if-modified-since" link will do a request to http://tweetplenty.com/test/test.php WITH modified if-modified-since header, the browser will return new content.
clicking "normal" again at this point returns the previously cached data, I would think that it should have refreshed the data after clicking the "if-modified-since" link.
If you want to checkout the test scripts themselves here you go: http://tweetplenty.com/test/test.zip
I think you want to modify the headers on all requests coming in. Check out example #2 on this page.
when making requests via the XmlHttpRequest to get any modified content from your server script you should append some variable that changes at the end of the querystring.
For example if your script is
then a way to call it via let's say Jquery Ajax is to make a request at
Usually [t] can be the current time in milliseconds or an other number.
In other words try to create a unique URL each time you send a request via the XMLHttpRequest Object.
As for the Cache-Control header there are more options that you should have a look at.
Regards,
Sounds like some level of caching between the jquery script and the PHP script. I would suspect browser-level caching. (although it could theoretically be proxy caching, I guess)
Have you tried using curl or a web browser to try your AJAX request manually?