store/cache ajax sent data to avoid repeated request

Attempting to answer this question directly: if the data you are returning is exactly the same each time, you can send cache control / expires headers with your AJAX response so that the browser knows not to request again for a while.

// ask the browser to cache this response, to reduce requests
$expires = 60 * 15;        // 15 minutes
header('Pragma: public');
header('Cache-Control: maxage=" . $expires);
header("Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');

But if you want different data each time, which it sounds like you do (via paging), then caching does nothing for you here. This answer on your other question explains why you would be better off grabbing small chunks at a time.

Leave a Comment