WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I developed a widget that offer a full blown archive search tool, where the user can select various options that are joined into an objects to be passed to WP_Query in an ajax action that returns the results data via JSON.

10 results are sent back to the page so pagination is needed. A new request is sent every time the page is turned. More here.

My question is: to decrease the request payload, I want that if the action is called after a page turn the information about the query is not sent but just the change page order is sent.

To achieve this i suppose the solution is to store the already sent query.

How is possible to do this?


share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.