简体   繁体   中英

How to get around the cached content refresh after http response code 304 is received?

I have a php application that uses prototypejs to do ajax polling with another php script, to check if there is new content or if content has been updated. It returns a http response code of 304 if the content has not changed.

This all works fine, however i just found out that browsers seem to refresh the content eventhough a response code 304 was sent. It seems this data is coming from the browser cache, which was filled with content from the last succesful response code 200 (when the poller found changed data).

The http rfc states: "If the status code is 304 (Not Modified), the cache uses the entity- body stored in the cache entry as the entity-body of this outgoing response".

Is there a way to get around this? Because eventhough no data was changed, people still see a slight flickering every time the code 304 is returned. I could use a response code 410 (Gone), which does not have this weird behaviour, but i don't think thats the way to do it.

My current ajax call is simple prototype code:

function showProcessing() {
  if(Ajax.activeRequestCount > 0)
    document.getElementById('inProgress2').style.display = 'none';
    document.getElementById('inProgress').style.display = 'inline';
}

function hideProcessing () {
  if(Ajax.activeRequestCount <= 0)
    document.getElementById('inProgress').style.display = 'none';
    document.getElementById('inProgress2').style.display = 'inline'; 
}

Ajax.Responders.register({
  onCreate: showProcessing,
  onComplete: hideProcessing
});

So if this behaviour can be disabled via prototype, then it's probably something that has to be done at the 'onComplete' part, but i haven't got a clue how.

请另外查看原始的相关网站http://codeigniter.com/wiki/AJAX_for_CodeIgniter/,因为它仅提供了有关htis的示例。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM